UITableView row height not drawing taller with text
I'm trying to mimic the address cell in Address Book / Contacts App.
I want a cell with style UITableViewCellStyleValue2
to display an address such as:
// 123 Fake St.
// Suite 555
// Denver CO, 80000
But actual cell isn't drawing the way I want. The label is drawing outside the bounds of the tableview row and part of top of the label is being cut off by the row directly above it.
Here's what I have so far:
cell.detailTextLabel.lineBreakMode开发者_开发技巧 = UILineBreakModeWordWrap;
cell.autoresizingMask = UIViewAutoresizingFlexibleHeight; //doesn't seem to do anything
self.tableView.rowHeight = 88.0f; // default is 44.0
cell.detailTextLabel.numberOfLines = 0; //unlimited lines
An NSLog
statement confirmed the rowHeight
is set to 88.0.
I realize a delegate method exists to change the row height. However, in my current app I only need this one cell to expand with the text, so I didn't feel it necessary to implement the delegate method.
Thank you for your help.
I don't think that setting row height this way (self.tableView.rowHeight = 88.0f;) for a single row will work. You should implement the delegate method which in your case is very simple, i.e.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return ([indexPath row] == MY_TALLER_CELL_ROW) ? 88.0f : 44.0f;
}
I think you'll probably have more luck not using the cell's default textLabel
and detailTextLabel
views; instead, create your own labels and add them to the cell's content view.
精彩评论