首先我用initWithCoder初始化表格,然后在单元格中加载数据。当数据源发生更改(这是Web服务)时,我想要重新加载表。只是为了测试我迷上了按钮动作,并添加了[self.tableView reloadData]
TableView reloadData不重新加载?
但是表不重新载入但数据源已被更改。如果我转到不同的视图并返回表格视图,则会显示新数据。有什么建议么?
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
self.titleList = [[SearchModel alloc] init];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[self.titleList load: ^(id json) {
[self.tableView reloadData];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}];
}
return self;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
self.tableView.delegate = self;
self.tableView.dataSource = self;
static NSString *CellIdentifier = @"title";
TitleDetailCell *cell = nil;
Model *title = nil;
title = [self.titleList get:indexPath.row];
if (cell == NULL)
{
cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
[cell movieTitleLabel].text = [title get:@"title"];
[[cell movieImageView] setImageWithURL: thumbnail];
}
return cell;
}
为什么你在cellForRowAtIndexPath方法中设置表代表和数据源?如果数据源没有设置在第一位,它将永远不会被调用 – Vladimir 2014-10-03 10:34:07
我应该在哪里设置它?在重新加载数据之前,我曾尝试将它放在viewDidApper – 2014-10-03 10:59:31
的任何位置。 viewDidLoad:是通常的地方。或者如果您使用IB - 最好在那里设置代理和数据源 – Vladimir 2014-10-03 11:19:39