objective-c - 为什么我的 UITableView 没有更新?

标签 objective-c ios

为什么我的 UITableView 没有更新?这是我尝试更新它的方式。

- (void)viewWillAppear:(BOOL)animated
{
    NSArray* arrValues = [self.defaults objectForKey:@"values"];
    [self.tableScores insertRowsAtIndexPaths:arrValues withRowAnimation:UITableViewRowAnimationNone];
}

arrValues 现在是一个 NSNumber 数组。我确定它不是空的。

最佳答案

- (void)viewWillAppear:(BOOL)animated

中调用 [tableScores reloadData];

更新1

此外,您需要在 header 中定义 arrValues。每次 viewWillAppear 时,您都在创建一个新实例,但您将无法在 Controller 的其余部分使用它。这是您除了在断点处什么都看不到的主要原因。

更新2

根据您在下面的评论,您还没有实现 cellForRowAtIndexPath:,这就是单元格的创建方式。下面是一个示例,但您可能想在网上搜索示例项目,因为这个 UITableView 的 101。在数组和 tableView 方面,您还有很多需要学习的地方。

示例 cellForRowAtIndexPath:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"FriendCellIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }

    cell.textLabel.text = [arrValues objectAtIndex:indexPath.row];

    return cell;
}

关于objective-c - 为什么我的 UITableView 没有更新?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10423698/

相关文章:

iphone - 检测 UIImageView 在 UITableViewCell 中的点击

objective-c - 未检测到已删除的条目-iOS

ios - 如何从视频 url iOS 获取可用的视频尺寸/质量?

ios - 添加到 configuration.protocolClasses 的自定义 NSURLProtocol 阻止了默认 url 协议(protocol)的工作

android - 如何检查目录和文件是否存在于 Phonegap 框架中?

ios - 存折集成 iOS(动态)

objective-c - NSMutableArray 版本使我的程序崩溃——为什么?

ios - 错误打印 user.default swift 3

ios - 当我在设备上运行时找不到 SQLite 文件

iphone - 如何使用动画在 iPhone 启动画面上添加两个文本