开发者

Height of a custom uitableviewcell

I have a NIB file with a custom UITableViewCell ins开发者_JS百科ide. I don't subclass UITableViewCell. In my tableViewController, I load my custom UITableViewCell and put it in my tableView. But when the tableView is shown, the height of my cell is the standard `UITableViewCell height. Why? In my NIB file, the height is 311.


You need to implement

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

in your table view delegate.


This method heightForRowAtIndexPath is valid only if we know the height values ​​for each cell. Often the custom cells have different heights and can dynamically create. If you do not know the height of the cell at the time of its creation, necessary to use additional methods. For exemple: we know the content view height for each custom cell, we can call the method reloadRowsAtIndexPaths. In method heightForRowAtIndexPath we must return value from array. When we get new value for each cells we must replace value at index in our array and call method reloadRowsAtIndexPaths. After that we get new value for each cells height.


If the height is the same for all table cells you would better do something like this:

self.tableView.rowHeight = 125.0;

in your custom TableViewController viewDidLoad or init method

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜