2013-10-18 37 views
3

我用魔杖将我的UITableViewCell的高度设置为我在故事板中指定的高度。获取UITableViewCell的高度

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{ 

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 

    return cell.frame.size.height; 
} 

使用此代码,应用程序崩溃。

+0

只有使用[tag:xcode]标签才能了解关于IDE本身的问题。谢谢! – Undo

回答

5

你必须明确地设置高度。在– tableView:heightForRowAtIndexPath:中调用-cellForRowAtIndexPath:会在两种方法之间创建一个无限循环。这是表视图常见的第一个错误。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{ 

    return 64; // some value 
}