开发者

Two different Cell Types in one UITableView

开发者 https://www.devze.com 2023-03-07 11:06 出处:网络
Hey everybody, I\'m very confused about how to use two different Cell Types in one UITableView with two sections. The first section should return a large Cell, with a lot of text, the other section sh

Hey everybody, I'm very confused about how to use two different Cell Types 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 navigate to other Views. I tried it like this:

- (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;
}

I set the height for the cells in the section开发者_如何学JAVAs 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' undeclared (first use this function). :( I really hope that you could help me. Thanks in advance


At the end of tableView:cellForRowAtIndexPath:, make it return nil; instead of return cell;.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号