使用系统默许UITableViewCell使用时的heightForRowAtIndexPath:indexPath方法
使用系统默认UITableViewCell使用时的heightForRowAtIndexPath:indexPath方法
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;后,该问题解决。