2013-10-18 40 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 
}