Вопрос:
Когда я устанавливаю rowHeight
для UITableView
, разве не должна изменяться и высота ячейки?
Вот ситуация, которая заставляет меня задуматься об этом:
Я хочу установить отдельную строку для каждой ячейки табличного представления внизу, более того, я хочу установить для нее высоту строки от 44
до 32
. Результат, который я хочу, выглядит следующим образом:
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];
}
// ...
}
Я попытался проверить cell.frame.size.height
, и, наконец, это было 44
. И тогда я заменяю строку
UIView * seperateLine = [[UIView alloc] initWithFrame:CGRectMake(10.0f, cell.frame.size.height - 1.0f, 300.0f, 1.0f)];
до
UIView * seperateLine = [[UIView alloc] initWithFrame:CGRectMake(10.0f, 31.0f, 300.0f, 1.0f)];
Это работает как первое изображение, показанное выше. Но the cell's height was still 44
, они (которые мы просто не можем видеть полностью) все еще перекрываются. То, что я сделал, просто добавил separate line
, где y
позиция равна 32
, но ее общая высота равна 44
.
Итак что вы думаете об этом? :