在tableView中获取指定行的高度

方法1:


CGRect frame = [tableView rectForRowAtIndexPath:indexPath];
NSLog(@"row height : %f", frame.size.height);

方法2:

int row = 1;
int section = 0;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:section];
float height = [self tableView:tableView heightForRowAtIndexPath:indexPath];

方法3:


-(CGFloat)getHeightAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.row == 0)
return 20.0;
else if(indexPath.row == 4)
return 40.0;
return 50.0; //Default
}

tableView:heightForRowAtIndexPath:中调用以上方法:
return [self getHeightAtIndexPath:indexPath];
并且你也可以在任意地方使用以上的方法,比如在button方法中:

-(IBAction)btnClick:(id)sender{
UIButton *btn=(UIButton *)sender;
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:btn.tag inSection:0];
CGFloat height=[self getHeightAtIndexPath:indexPath];
}

参考链接:
How can I get the height of a specific row in my UITableView

你可能感兴趣的:(在tableView中获取指定行的高度)