【发布时间】:2015-02-16 17:00:44
【问题描述】:
这是我的 UITableView 代码
在 viewDidLoad 中
self.audioHistoryTableView = [[UITableView alloc] init];
self.audioHistoryTableView.delegate = self;
self.audioHistoryTableView.dataSource = self;
表格视图
#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"numberOfRowsInSection");
NSLog(@"tableeeeeeee %lu",(unsigned long)[audioHistory count]);
return [audioHistory count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"cellForRowAtIndexPath");
NSString *CellIdentifier = @"historyCell";
UITableViewCell *cell = (UITableViewCell *)[self.audioHistoryTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Configure the cell...
NSString *audio = [audioHistory objectAtIndex:indexPath.row];
cell.textLabel.text = audio;
return cell;
}
当我添加数据并调用 reload 时
NSArray *newItem = [NSArray arrayWithObject:@"new audio!"];
NSLog(@"new item : %@",newItem);
[audioHistory addObjectsFromArray:newItem];
[self.audioHistoryTableView reloadData];
我知道这不起作用,因为我添加了新数据并更改到其他页面,当返回此页面时显示添加的数据。
【问题讨论】:
-
你在使用故事板吗?
-
能否将整个方法添加到您更新数据并调用重新加载的问题中?这个方法是在 audioHistoryTableView 的视图控制器中还是在另一个视图控制器中?
-
在您致电
reloadData后,您的日志消息会说什么?他们在打印吗?他们打印的东西是否正确? -
@lightice11 是的,使用故事板
-
@LyndseyScott 它在另一个视图控制器中。我只是添加 UITableView,而不是 UITableViewController
标签: ios uitableview cell reloaddata