Hi everyone, I am very confused about how to use two different types of cells in one UITableView with two sections. The first section should return a large cell with a lot of text, the other section should return three cells to go to other views. I tried this as follows:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
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];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [array objectAtIndex:row];
return cell;
}
return cell;
}
I set the height for the cells in the sections here:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSUInteger section;
if (section == 0) {
return [indexPath row] + 80;
}
else
{
return [indexPath row] + 44;
}
}
I get this error: "cell" uneclared (use this function first). :( I really hope you could help me. Thanks in advance
source
share