Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 9 - iOS 11 UITableView rows are empty

Ever since the new iOS 11 update, I have an app that will show blank tableview rows on the simulator and device. Even the row separators will not show for any of the rows that are supposed to be there. If I change the simulator to an older iOS version, the rows will show fine. No changes to code or storyboard.

The rows still have the data, meaning I can tap on one of the blank rows and it will execute the code and contain the information I was expecting.

It appears that other scenes that I have where the tableview is placed on a view and I don't use the built in text label work fine. Just this tableview class using the built in 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

like image 721
Kryckter Avatar asked Sep 27 '17 15:09

Kryckter


1 Answers

I had this issue as well with IOS 11 showing blank cells.. but in IOS 10 was fine. My issue was that I was using a gradient which for whatever reason stopped the cell text from being shown. Removing the gradient resolved the blank cells.

like image 123
Matt Avatar answered Oct 10 '22 04:10

Matt