在heightForRowAtIndexPath之后获取单元格中的更新行高

aka*_*hsr 5 cocoa-touch objective-c tableview ios

我正在尝试访问单元格的setProperty中的TableViewCell的高度.

我正在通过xib创建单元格,然后根据返回的值更改高度 heightForRowAtIndexPath

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {    
    return 200;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
        RightGuideCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
        cell.ticks = @[@"1",@"1",@"1",@"1",@"1",@"1",@"1"];
        return cell;
}
Run Code Online (Sandbox Code Playgroud)

这是我单元格中的属性.

- (void)setTicks:(NSArray *)ticks {
    _ticks = ticks;
    CGFloat height = self.frame.size.height; //Value is 44 (size in xib)
}
Run Code Online (Sandbox Code Playgroud)

如何heightForRowAtIndexPath在单元格中获得200(设置)?

il *_*tto 0

它以不同的方式运作。tableview 使用 heightForRowAtIndexPath 来了解为单元格保留多少空间,以便它可以按照所需的方式布局单元格。当您从 xib 创建单元格时,它具有您绘制的大小,与表格视图为单元格保留的大小无关。

因此,如果您希望它与表视图中的给定空间匹配,则必须在创建单元格(双端队列...)时或在 setTicks 方法中调整单元格的大小(更改框架),因为这两个信息不相关。