iOS 7.1 tableView reloadData没有正确更新tableView

时间:2014-03-16 23:27:58

标签: ios iphone objective-c uitableview ios7.1

仅在iOS 7.1中reloadData发生了奇怪的事情。此代码在iOS 7.0中完美运行。我更新了一些变量,然后调用reloadData

myNum = 12;
[self.tableView reloadData];

然后在cellForRowAtIndexPath

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

这不再在7.1中正确更新按钮标题,但在7.0中工作正常。此外,如果我弹出AlertDialog,它将成功重新加载具有正确标题的tableView按钮。 AlertDialog调用的哪一部分更新/刷新底层屏幕?我可以手动拨打电话而不会实际弹出AlertDialog吗?

我已尝试调用[self.view setNeedsDisplay]setNeedsLayout。没有帮助。

3 个答案:

答案 0 :(得分:3)

玩了一会儿后,我发现它与启用的按钮有关。对于没有正确更新的行,我禁用了按钮。我刚刚添加了

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

所以我启用然后立即禁用,现在他们正确更新。

答案 1 :(得分:0)

我遇到了同样的问题。

通过为UIControlStateNormalUIControlStateSelectedUIControlStateHighlighted设置相同的标题来解决。

看起来更干净的解决方案。

答案 2 :(得分:0)

在我的情况下,这段代码为我做了工作:

[cell.buttonName setNeedsLayout];

我再次要求按钮布局。

相关问题