I've created a custom cell class using these instructions: http://www.bdunagan.com/2009/06/28/custom-uitableviewcell-from-a-xib-in-interface-builder/
Everything worked great, except I have one small issue. The height of the background image of the cell is 100px. However when I 开发者_运维知识库launch the app, it seems to be using default height of cells, which is around 50px or so. How can I fix this? My custom cell is loaded from an XIB, and in that XIB the cell has the desired height of 100px, but it's still using default height in simulator.
In your Table View Controller you need to override the heightForRowAtIndexPath and set the height to 100.0px as so:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 100.0f;
}
Set the rowHeight
property on your instance of UITableView
. It accepts a CGFloat
.
If all of your cells will be of the same height it is best to use the rowHeight property instead of the tableView:heightForRowAtIndexPath:
delegate method. Using the delegate method incurs a cost on scrolling performance.
self.tableView.rowHeight = 100.0f;
You still need to return the new height from heightForRowAtIndexPath.
Change the row height of UITableView (not your custom cell) in your interface builder or programmatically.
http://developer.apple.com/library/iOS/#documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html
I don't think you have to override heightForRowAtIndexPath. Also based on http://iphoneincubator.com/blog/windows-views/the-right-way-to-set-the-height-of-tableviewcells, you will get better performance without using heightForRowAtIndexPath.
精彩评论