iOS项目开发中使用系统默认的UITableViewCell时,Delegate中的方法- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;须慎用。
项目中使用系统默认的UITableViewCell:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *tableViewIdentifier = @"TableViewCellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableViewIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableViewIdentifier];
}
...
return cell;
}
设置Row的高度:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 44 * (isPad ? 2.4 : 1.0);
}
OS是7.1.2的iPhone5和iPhone5s中,前者正常显示,后者TableView中不能显示。经过调试,原因是对应的contnetSize.height为0。根本原因就不深入查找了。
当注释方法- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;后,该问题解决。
在iOS项目开发中,使用系统默认的UITableViewCell时,若在Delegate中定义了高度计算方法,可能会导致特定设备(如iPhone5s)显示异常。通过移除此方法,问题得以解决。
270

被折叠的 条评论
为什么被折叠?



