我正在尝试实现分组式样的UITableView,比如Contact apps detailedView。我想最顶层的单元格是透明的,并在底部有一个UISegemtedControl。使用多个自定义的UITableViewCells
当我尝试创建两种不同类型的自定义单元格时,即使使用两个不同的cellIdentifiers,也只加载第一个。
希望som指导。或者为同一主题提供一些很好的教程提示。
- (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;
}
你的'numberOfSectionsInTableView:'方法返回什么? – omz
@omz它返回2. – Silversnail
好吧,我假设你也许只有一个部分有两行...再次查看你的代码,我注意到你加载单元格1和单元格2的方式完全相同在“DetailCellView”笔尖中的“UITableViewCell”类型的第一个对象。因此,在这两种情况下你都会得到同样的细胞。 – omz