iPhone开发笔记 (4) 如何改变UITableViewCell的行高

在使用UITableView的时候,UITableViewCell的高度可能要改变。改变行高有两种情况,第一种是改变所有的行高。第二种是改变特定行的行高。

第一种,改变所有行的行高。就是类似下面的效果。

iPhone开发笔记 (4) 如何改变UITableViewCell的行高

这里要使用UITableViewDelegate的方法:

//设置rowHeight - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 91.5; }第二种,如果要指定改变某个行的行高。就类似下面的效果。

iPhone开发笔记 (4) 如何改变UITableViewCell的行高


只要对上面的方法做一下修改如下:

//设置rowHeight - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section == 0 && indexPath.row == 0) { return 220; } else { return 40; } }