开发者社区> 问答> 正文

关于UITableView 设置行高度崩溃

iPhone应用中有四种单元,每个高度都不同。在给每个tableView设置高度的方法崩溃。

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
    NSLog(@"%@", cell);
    if([cell.reuseIdentifier isEqualToString:PastEventWICellIdentifier]){
        return 56;
    }
    if([cell.reuseIdentifier isEqualToString:PastEventWOICellIdentifier]){
        return 56;
    }
    if([cell.reuseIdentifier isEqualToString:EventWICellIdentifier]){
        return 112;
    }
    if([cell.reuseIdentifier isEqualToString:EventWOICellIdentifier]){
        return 112;
    }
    return 56;
}

展开
收起
爵霸 2016-03-19 14:20:37 2092 0
1 条回答
写回答
取消 提交回答
  •  操作方法:   UITableView加载的顺序是先得到表的行的高度,也就是先调用heightForRowAtIndexPath方法,然后再调用cellForRowAtIndexPath,所以我们有两个办法实现自定义cell高度:   一:改变它的加载顺序,或者说白了就是计算好cell高度后,再次让它加载heightForRowAtIndexPath方法;   二:直接在heightForRowAtIndexPath计算,做判断,直接返回对应的高度。

    2019-09-18 20:27:48
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载