我正在尝试实现分组样式的 UITableView,例如联系人应用 detailedView。我希望最上面的单元格是透明的,并在底部有一个 UISegemtedControl。
当我尝试创建两种不同类型的自定义单元格时,即使我使用了两个不同的 cellIdentifier,也只有第一个被加载。
非常感谢您的指导。或者针对同一主题的一些很好的教程技巧。
- (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
的第一个对象,您以完全相同的方式加载单元格 1 和单元格 2。因此,在这两种情况下您都会得到相同的单元格。
关于ios - 使用多个自定义 UITableViewCells,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6982419/