0

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

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

arrValues现在是一个 NSNumbers 数组。我确信它不是空的。

4

1 回答 1

4

呼入[tableScores reloadData];_- (void)viewWillAppear:(BOOL)animated

更新 1

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

更新 2

根据您在下面的评论,您尚未实现cellForRowAtIndexPath:单元格的创建方式。下面是一个示例,但您可能想在网上搜索示例项目,因为这个UITableView 的 101。当涉及到数组和 tableViews 时,你还需要学习很多东西。

例子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;
}
于 2012-05-03T00:54:45.513 回答