首先我用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