UITableViewCell frame height is always 44px

I set the cell height using the heightForRowAtIndexPath: method returns 100. But in the cellForRowAtIndexPath method, the cell frame height is always 44px.

Below is my code.

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 100; } - (int) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 10; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; } [cell setBackgroundColor:[UIColor redColor]]; [cell.contentView setBackgroundColor:[UIColor redColor]]; cell.textLabel.text = [NSString stringWithFormat:@"%d", indexPath.row]; NSLog(@"%f %f", cell.frame.size.height, cell.contentView.frame.size.height); return cell; } 

The NSLog statement prints "44px 44px".

I can get the correct height using this operator

 CGFloat height = [tableView heightForRowAtIndexPath:indexPath]; 
+4
source share
1 answer

Your delegation method will not be called when the cell is allocated. initWithStyle allways returns cells with a height of 44 unless you overwrite them in a subclass.

+4
source

All Articles