【问题标题】:UITableView second prototype cell does not appear to be respecting custom height?UITableView 第二个原型单元格似乎不尊重自定义高度?
【发布时间】:2015-08-09 19:32:41
【问题描述】:
我正在使第二个原型单元出队,但单元的高度似乎没有得到尊重。
谁能引导我朝着正确的方向前进?我已经尝试搜索谷歌无济于事。
问题已经解决了,我的解决方案是用代码实现的:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
CGFloat height;
if ([indexPath row] == 0) {
height = 170.0f;
}
else {
height = 72.0f;
}
return height;
}
【问题讨论】:
标签:
ios
uitableview
cocoa-touch
storyboard
uikit
【解决方案1】:
您需要实现表格视图委托方法heightForRowAtIndexPath: 才能更改单元格的高度。您不能仅在情节提要中做到这一点。
【解决方案2】:
记住
storyboards 或 xib 无法在没有代码的情况下将单元格出列,因此您必须设置委托并写入代码tableView:heightForRowAtIndexPath,
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
CGFloat height;
if ([indexPath row] == 0) {
height = 100.f;
}
else {
height = 50.f;
}
return height;
}