两个不同的单元格类型在一个UITableView [英] Two different Cell Types in one UITableView

查看:83
本文介绍了两个不同的单元格类型在一个UITableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,大家,我很困惑,如何使用两个不同的单元格类型在一个UITableView与两个部分。第一部分应该返回一个大Cell,有很多文本,其他部分应该返回三个单元格,导航到其他Views。我尝试了这样:

   - (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:@CustomTableCellowner: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:@cTableViewCellowner: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;
}



我在这里的部分设置单元格的高度:

   - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{
NSUInteger section;
if(section == 0){
return [indexPath row] + 80;
}
else
{
return [indexPath row] + 44;
}

}

'undeclared(首先使用此函数)。 (我真的希望你能帮助我。

解决方案

:cellForRowAtIndexPath:,使它 return nil; 而不是 return cell; p>

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 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' 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;.

这篇关于两个不同的单元格类型在一个UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆