大家好,我对如何在一个具有两个部分的 UITableView 中使用两种不同的单元格类型感到非常困惑。第一部分应返回一个大单元格,其中包含大量文本,另一部分应返回三个单元格,以导航到其他视图。我尝试过这样的:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//NSUInteger section;
static NSString *CellIdentifier1 = @"CellIdentifier";
static NSString *CellIdentifier2 = @"Cell";
if (indexPath.section == 0) {
CustomTableCell *cell = (CustomTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
if (cell == nil)
{
[[NSBundle mainBundle] loadNibNamed:@"CustomTableCell" owner:self options:nil]; cell = [self customTableCell];
[self setCustomTableCell:nil];
}
return cell;
}
else if (indexPath.section == 1) {
cTableViewCell *cell = (cTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];
if (cell == nil)
{
[[NSBundle mainBundle] loadNibNamed:@"cTableViewCell" owner:self options:nil];
cell = [[cTableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier2];
[self setCustomTableCell:nil];
}
// Configure the cell...
NSUInteger row = [indexPath row];
cell.textLabel.text = [array objectAtIndex:row];
return cell;
}
return cell;
}
我在此处设置了各部分中单元格的高度:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger section;
if (section == 0) {
return [indexPath row] + 80;
}
else
{
return [indexPath row] + 44;
}
}
我收到此错误:'cell' 未声明(首先使用此函数)。 :( 我真的希望你能帮助我。提前致谢
在......的最后tableView:cellForRowAtIndexPath:
, 做了return nil;
代替return cell;
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)