使用多个自定义的UITableViewCells

我正在尝试实现分组样式的UITableView,如联系应用程序detailedView。 我想最上面的单元格是透明的,并在底部有一个UISegemtedControl。

当我尝试创build两种不同types的自定义单元格时,即使使用两个不同的cellIdentifiers,也只会加载第一个自定义单元格。

将不胜感激索姆的指导。 或者针对同一主题的一些很好的教程技巧。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { /* UIView *backView = [[UIView alloc] initWithFrame:CGRectZero]; backView.backgroundColor = [UIColor clearColor]; cell.backgroundView = backView; [backView release]; */ static NSString *cellIdentifier1 = @"DetailCellStyle1"; static NSString *cellIdentifier2 = @"DetailCellStyle2"; if (indexPath.section == 0) { // Load from nib DetailCellViewController *cell = (DetailCellViewController *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier1]; if (cell == nil) { NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"DetailCellView" owner:nil options:nil]; for (id currentObject in topLevelObjects) { if ([currentObject isKindOfClass:[UITableViewCell class]]) { cell = (DetailCellViewController *) currentObject; break; } } } return cell; } else { // Load from nib DetailCellViewController2 *cell = (DetailCellViewController2 *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier2]; if (cell == nil) { NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"DetailCellView" owner:nil options:nil]; for (id currentObject in topLevelObjects) { if ([currentObject isKindOfClass:[UITableViewCell class]]) { cell = (DetailCellViewController2 *) currentObject; break; } } } return cell; } return nil; } 

通过在“DetailCellView”nib中获取UITableViewCelltypes的第一个对象,以完全相同的方式加载单元格1和单元格2。 因此,在这两种情况下你都得到相同的单元格。

那么,说实话我也不确定,但是,负载调用只有apears是有效的,当单元格为零,也许尝试加载第二个作为其他的if(cell == nil)调用…因为在代码的最后,你将它设置为零…所以也许:-)