Adam Johns
Adam Johns

Reputation: 36373

iOS 7.1 tableView reloadData not updating tableView correctly

Something strange is happening for me with reloadData ONLY IN iOS 7.1. This code works PERFECTLY in iOS 7.0. I update some variables and then call reloadData:

myNum = 12;
[self.tableView reloadData];

then in cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    … 
    [cell.leftScoreButton setTitle:[NSString stringWithFormat:@"%d", myNum] forState:UIControlStateNormal];
    cell.leftScoreButton.enabled = NO;
    … 

This is no longer updating the button title correctly in 7.1, but it works fine in 7.0. Also if I pop up with an AlertDialog, then it will successfully reload the tableView button with the correct title. What part of AlertDialog calls update/refresh the underlying screen? Can I call that manually without actually popping up with an AlertDialog?

I have already tried calling [self.view setNeedsDisplay] and setNeedsLayout. Neither helped.

Upvotes: 0

Views: 1463

Answers (3)

cessmestreet
cessmestreet

Reputation: 2318

In my case this code did the work for me:

[cell.buttonName setNeedsLayout];

I asked the button to be layout again.

Upvotes: 0

megimix
megimix

Reputation: 78

I had the same issue.

Resolve by setting same title for UIControlStateNormal, UIControlStateSelected and UIControlStateHighlighted.

Looks more clean solution.

Upvotes: 0

Adam Johns
Adam Johns

Reputation: 36373

After playing around for a while I noticed it is related to the buttons being enabled. For the row that wasn't updating properly I had the buttons disabled. I just added

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    … 
    [cell.leftScoreButton setTitle:[NSString stringWithFormat:@"%d", myNum] forState:UIControlStateNormal];
    cell.leftScoreButton.enabled = YES;
    cell.leftScoreButton.enabled = NO;
    … 

so I enable and then immediately disable, and now they update properly.

Upvotes: 3

Related Questions