方法1:
<pre>
CGRect frame = [tableView rectForRowAtIndexPath:indexPath];
NSLog(@"row height : %f", frame.size.height);
</pre>
方法2:
<pre>
int row = 1;
int section = 0;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
float height = [self tableView:tableView heightForRowAtIndexPath:indexPath];
</pre>
方法3:
<pre>
-(CGFloat)getHeightAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.row == 0)
return 20.0;
else if(indexPath.row == 4)
return 40.0;
return 50.0; //Default
}
</pre>
在tableView:heightForRowAtIndexPath:
中调用以上方法:
<code>return [self getHeightAtIndexPath:indexPath];</code>
并且你也可以在任意地方使用以上的方法,比如在button方法中:
<pre>
-(IBAction)btnClick:(id)sender{
UIButton *btn=(UIButton *)sender;
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:btn.tag inSection:0];
CGFloat height=[self getHeightAtIndexPath:indexPath];
}
</pre>
参考链接:
How can I get the height of a specific row in my UITableView