自定义单元格未通过heightforrowatindexpath返回高度

时间:2015-08-28 20:40:00

标签: ios objective-c

我正在努力获得动态细胞高度。我已经以编程方式创建了一个自定义单元格。现在我希望单元格的高度发生变化,但似乎总是返回np.mgrid[-10:5:50j, -2:2:50j]这是默认的tableviewcell高度。这是为什么?

44

自定义单元格

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.reminderTableView registerClass:[ReminderTableViewCell class] forCellReuseIdentifier:@"Daybreak-Cell"];
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath;
{
    if (indexPath.row > 3) {
        return 60;
    }
    return 70;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:@"Custom-Cell" forIndexPath:indexPath];

    ...
    return cell;
 }

2 个答案:

答案 0 :(得分:0)

从iOS7开始我需要做的就是:

self.tableView.estimatedRowHeight = 100.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;

要使单元格具有动态高度,也不要忘记在单元格中从上到下放置约束

答案 1 :(得分:0)

必须确保将表的委托设置为包含

的类
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath;
{
    if (indexPath.row > 3) {
        return 60;
    }
    return 70;
}

因为这种方法适合我

相关问题