How to change height of a grouped tableViewCell?
I'm trying to display address as its displayed in Contact app of iPhone. so it seems i need a cell with height three times of a regular cell. as its always going to be same i just need to apply a fixed height to the code. but i don't know how to do it. my current code is
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *address = [NSString stringWithFormat:@"%@\n"@"%@ %@ %@\n"@"%@", dispAddress, dispCity, dispState, dispZip, dispCountry];
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.detailTextLabel.numberOfLines = 3; // 开发者_运维知识库0 means no max.
cell.detailTextLabel.text = address;
return cell;
}
To set all cells to the same fixed height, in viewDidLoad or some other appropriate place, do:
self.tableView.rowHeight = 100;
To set cells to different heights based on index path, use the heightForRowAtIndexPath delegate method:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ((indexPath.section == 0) && (indexPath.row == 0))
return 100;
else
return 44;
}
精彩评论