使用多个自定义的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中获取UITableViewCell
types的第一个对象,以完全相同的方式加载单元格1和单元格2。 因此,在这两种情况下你都得到相同的单元格。
那么,说实话我也不确定,但是,负载调用只有apears是有效的,当单元格为零,也许尝试加载第二个作为其他的if(cell == nil)
调用…因为在代码的最后,你将它设置为零…所以也许:-)
- 如何使浏览器在ios中滚动
- iOS UITableViewCellAccessoryCheckmark每次滚动都可见
- 在cellForRowAtIndexPath中调用heightForRowAtIndexPath?
- IOS 7如何使用UITableView的scrollToRowAtIndexPath
- 如何避免UITableViewCell重复添加自定义标签时,TableView滚动?
- 如何按照字母顺序将NSArray分割成UITableView部分
- alignmentUITableView中的文本
- 从UITableView删除最后一行 – 崩溃与NSInternalInconsistencyError
- UITableView设置隐藏的tableview行