为什么我的 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/