Xcode 9 - iOS 11 UITableView Lines Empty

Since the creation of the new iOS 11 update, I have an application that will show empty table rows on the simulator and device. Even line separators will not be displayed for any of the lines that should be there. If I change the simulator to an earlier version of iOS, the lines will be displayed in order. No changes to the code or storyboard.

The lines still have data, that is, I can click on one of the empty lines, and it will execute the code and will contain the information that I expected.

It seems that the other scenes that I have where the tableview fits in the view and I don't use the inline text label works fine. It's just that this tableview class uses an inline text label.

Here is my code for the tableview class ...

@interface BunkPickTableViewController () @end @implementation BunkPickTableViewController @synthesize appDelegate, delegate, bunkPassedValue; - (void)viewDidLoad { [super viewDidLoad]; UIView *backgroundView = [[UIView alloc] initWithFrame:self.view.bounds]; appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; CAGradientLayer *bgLayer = [BackgroundLayer tanGradient]; bgLayer.frame = self.view.bounds; [self.view.layer insertSublayer:bgLayer atIndex:0]; self.tableView.backgroundView = backgroundView; [self.navigationController.navigationBar setTintColor:[UIColor blackColor]]; self.title = @"Bunk Codes"; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[self navigationController] setNavigationBarHidden:NO animated:NO]; [self.tableView reloadData]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [appDelegate.bunkArray count]; } - (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]; cell.textLabel.textAlignment = NSTextAlignmentCenter; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; cell.backgroundColor = [UIColor clearColor]; } Bunk *bunkObj = [appDelegate.bunkArray objectAtIndex:indexPath.row]; cell.textLabel.text = bunkObj.bunkId; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark; [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; Bunk *bunkObj = [appDelegate.bunkArray objectAtIndex:indexPath.row]; [delegate dismissBunkPop:bunkObj.bunkId]; [self.navigationController popViewControllerAnimated:YES]; } @end 

TableView Settings Image

+7
objective-c xcode ios11
source share
4 answers

I also had a problem with iOS 11 showing empty cells. But iOS 10 was fine. My problem was that I used a gradient, which for some reason stopped displaying the cell text. Removing the gradient allowed empty cells.

+3
source share

Perhaps this is due to the fact that your tableView falls under bgLayer .

The problem seems to be in self.view.layer insertSublayer:bgLayer atIndex:0 . I used insertSubview at index 0 and I had the same problem. This is probably a bug in iOS 11 - if your tableView is defined in the storyboard, it always pushes back.

The best solution is to place bgLayer inside tableView.backgroundView .

Note: You can also solve this problem by calling sendSubviewToBack on bgLayer in viewDidAppear , but unfortunetaly, tableview cells are moved back to each reloaddata table, so this is not a good solution.

+3
source share
 CAGradientLayer *gradient = [CAGradientLayer layer]; gradient.frame = self.tableView.bounds; gradient.colors = @[(id)[UIColor blackColor].CGColor, (id)[UIColor grayColor].CGColor, (id)[UIColor lightGrayColor].CGColor]; UIView *bgView = [[UIView alloc] initWithFrame:self.tableView.bounds]; [self setBackgroundView:bgView]; [bgView.layer insertSublayer:gradient atIndex:0]; [self.tableView setBackgroundView:bgView]; 

Setting the gradient layer to view as a table for the view is resolved for me. Upto iOS 10 we can directly insert a sublevel in a tableView, but in iOS 11 a layer should only be inserted in the background view of UITableVIew.

0
source share

Combined with the above manipulation of the view in the tableview, this problem can also occur if your project existed before Xcode 9, and then you checked the โ€œUse Layout Layout Guidesโ€ checkbox on your storyboard. Try unchecking this box and see if it works.

0
source share

All Articles