UITableView error in iOS8 when selecting items with a Height rating other than rowHeight

I am working on a project that is iOS7 and iOS8. And I came across this error on iOS8, where the tableview will โ€œjumpโ€ when selecting an item.

This error is present only where the oriented height is set, and it differs from the height of the line.

Here are two gifs of the same code in iOS8 and iOS7. First iOS8:

TableView in iOS8

And now in iOS7:

TableView in iOS7

I made an example project showing the error here: https://github.com/bjarkehs/TableViewiOS8Bug

I'm not sure that I just missed something, but I was stuck in this problem and I could not find anything.

Here are my tableView methods:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 3; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (section == 1) { return 30; } return 20; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; } cell.textLabel.text = [NSString stringWithFormat:@"%@ %ld", @"Wat", indexPath.row]; return cell; } - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath { return 45.f; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 50.f; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self.navigationController pushViewController:[UIViewController new] animated:YES]; } 

Here is an example viewcontroller where the calculated height is not hard-coded, which indicates the same problem:

 #import "ViewController.h" @interface ViewController () @property (weak, nonatomic) IBOutlet UITableView *tableView; @end @implementation ViewController { NSMutableArray *_items; CGFloat _estimatedHeight; } - (void)viewDidLoad { [super viewDidLoad]; self.tableView.delegate = self; self.tableView.dataSource = self; _estimatedHeight = 70.f; CGFloat randomOffset = 30.f; _items = [NSMutableArray new]; for (NSInteger i = 0; i < 3; i++) { NSMutableArray *tempItems = [NSMutableArray new]; for (NSInteger j = 0; j < 30; j++) { NSInteger offset = arc4random_uniform(randomOffset); [tempItems addObject:@(_estimatedHeight + (randomOffset/2) - offset)]; } [_items addObject:tempItems]; } // Do any additional setup after loading the view. } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 3; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (section == 1) { return 30; } return 20; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; } cell.textLabel.text = [NSString stringWithFormat:@"%@ %ld", @"Wat", indexPath.row]; return cell; } - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath { return _estimatedHeight; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return [[[_items objectAtIndex:indexPath.section] objectAtIndex:indexPath.row] floatValue]; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self.navigationController pushViewController:[UIViewController new] animated:YES]; } @end 
+7
ios objective-c uitableview ios8
source share
1 answer

Your implementation for the Estimated Height for the Index is not what I saw before. Take a look at this, where I described this template in detail ...

Approximate Height Example

-one
source share

All Articles