Question:
When I set the rowHeight for UITableView, shouldn’t the height of cell changed as well?
Here is the situation that leads me to think about it:
I want to set a separate line for each table view cell at bottom, what’s more, I want to set the row height for it from 44 to 32. The result I want is like below:

Row height setting is done correctly:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.tableView setRowHeight:32.0f];
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
//...
}
// Even use the delegate of UITableView
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 32.0f;
}
However, when I was adding separate line for cell, I met a issue: I want to set the separate line at bottom of the cell, so I set the y position by cell.frame.size.height - 1.0f. Unfortunately, the result shown as below:

When I did selecting, cell changed like below:
1. Selected row No.1:
2. Selected row No.2:
3. Selected row No.3:
It seems that the height of cell before selected was 44, when selected, it changed to 32. They were overlapped one by one like cards, right? Weird!
The main code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
[cell.textLabel setFont:[UIFont fontWithName:@"Futura-Medium" size:15.0f]];
UIView * seperateLine = [[UIView alloc] initWithFrame:CGRectMake(10.0f, cell.frame.size.height - 1.0f, 300.0f, 1.0f)];
NSLog(@">>>>>>>>>>>>>>>> %f", cell.frame.size.height);
[seperateLine setBackgroundColor:[UIColor grayColor]];
[cell.contentView addSubview:seperateLine];
[seperateLine release];
}
//...
}
I tried to check the cell.frame.size.height, and finally it was 44. And then, I replace the line
UIView * seperateLine = [[UIView alloc] initWithFrame:CGRectMake(10.0f, cell.frame.size.height - 1.0f, 300.0f, 1.0f)];
to
UIView * seperateLine = [[UIView alloc] initWithFrame:CGRectMake(10.0f, 31.0f, 300.0f, 1.0f)];
It worked as the first image shown above. But the cell's height was still 44, they(which we just cannot see totally) ware still overlapped. What I had done is just added a separate line at where y position is 32 but its total height is 44.
So what do you think about this? 😕



Problem:
According to apple’s HIG the default tapable area is 44, so by default all control has 44 height.
you define new
UITableViewCellinsidewhich is by default 44 and you change nothing in
UITableViewCell‘s frame and return it.Solution:
try setting the frame size of the
UITableViewCelli.ecell.frame = CGRectMake(0.0f, 0.0f, 320.0f, 32.0f)