问题描述
我正在尝试实现像联系人应用程序详细视图这样的分组样式 UITableView.我希望最顶部的单元格是透明的,并在底部有一个 UISegemtedControl.
I´m trying to achieve a grouped styled UITableView like the Contact apps detailedView. I want the top most cell to be transparant and have a UISegemtedControl at the bottom.
当我尝试创建两种不同类型的自定义单元格时,即使我使用了两种不同的 cellIdentifier,也只会加载第一种.
When I try to create two different types of custom cells, only the first one is loaded even though i use two different cellIdentifiers.
希望得到一些指导.或者针对同一主题的一些不错的教程提示.
Would appreciate som guidance. Or some good tutorial tips for the same topic.
- (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" 笔尖中获取 UITableViewCell
类型的第一个对象,您以完全相同的方式加载单元格 1 和单元格 2.因此,您在两种情况下都会获得相同的单元格.
You load cell 1 and cell 2 in exactly the same way by taking the first object of type UITableViewCell
in the "DetailCellView" nib. Therefore, you're getting the same cell in both cases.
这篇关于使用多个自定义 UITableViewCells的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!