我有一个UITableView,UITableViewCell从不同的Nib文件加载,当用户点击或双击一个单元格,即有三个不同高度的Nib文件,一个用于普通,点击和双击. 如何在heightForRowAtIndexPath中识别加载的笔尖:用
如何在heightForRowAtIndexPath中识别加载的笔尖:用于动态设置行高?
您可以在heightForForAtIndexPath中将单元格出列并检查它的高度:- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *cellId = @"Cell";//set cell ID here based on your view controller's logic UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:cellId]; return cell.bounds.size.height; }
如果您关心性能,可以将出列的单元格缓存在字典中.在Retrieve custom prototype cell height from storyboard中对此方法进行了更详细的讨论(与标题可能暗示的相反,不需要使用故事板).