为一个tableView使用多个UITableViewCells

时间:2016-07-14 02:52:24

标签: ios objective-c uitableview storyboard

我不确定在使用多个自定义单元格视图时是否以正确的方式设置UITableView。我似乎有我的表工作但是,我认为重复使用单元格后,您加载视图时看到的第一个单元格与第一个单元格大小相同,该单元格应该是唯一一个大小加倍的单元格。一旦我滚动它们并将它们备份,它们就会达到为它们设置的大小。

有没有正确的方法呢?我已经浏览了其他形式并尝试了他们的方式,但这是封闭的,我已经让它与这一个缺陷一起工作。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{    
    static NSString *CellIdentifier1 = @"profileCell";
    static NSString *CellIdentifier2 = @"profileCells";

    if (indexPath.section == 0) {
        PFProfileTableCellView * cell = (PFProfileTableCellView *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier1];

        //only one row in this section
        return cell;

    } else{
        PFWallPostTableViewCell * cell = (PFWallPostTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier2];


        return cell;
    }
}

Last cell is the right size

1 个答案:

答案 0 :(得分:1)

使用此UITableView委托方法- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;并根据tableview的部分返回行高,如下例所示

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.section == 0) {
        return 100.0;
    }
    return 50.0;
}
相关问题