我正在制作一个使用 UITableView
和 UITableViewController
的应用程序。然而,当我在 UITableViewController
中调用 [self.tableView reloadData];
时,什么也没有发生(tableView: cellForRowAtIndexPath:
没有被调用)。我该怎么办?
- (void) UserChangedAmmountAndCurrency: (NSNotification*) notification {
self.localBank.activeAmmount=((NSNumber*)[notification.userInfo objectForKey:@"newAmmount"]).doubleValue;
self.localBank.activeCurrency=[self.localBank.worldBank requestCurrencyForLocalBank:((NSString*)[notification.userInfo objectForKey:@"newISO4217Currency"])];
[self.tableView reloadData];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSNumber *ammount= [self.localBank ammountForElementAtIndex:indexPath.row];
VIPCurrency* currency=[self.localBank currencyForElementAtIndex:indexPath.row];
static NSString *CellIdentifier = @"cellWithCurrencyAndAmmount";
VIPConversionCell* cell=[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.longCurencyIdentifier.text=currency.longName;
cell.shortCurrencyIdentifier.text=currency.shortName;
cell.textfieldForAmmount.text=ammount.stringValue;
return cell;
}
编辑:我做了一些额外的测试。我测试了tableview数据源和代理是调用reload方法的视图控制器,这很好。我还注意到了一些其他奇怪的事情。当调用reloadData时,既没有调用numberOfSectionsInTableView:
也没有调用numberOfRowsInSection:
。我觉得在调用reloadData之前我可能没能做一件基本的事情,但我不知道是什么。难道我必须以某种方式明确地将单元格设置为过时吗?
编辑:我还检查了该方法是否在主线程中调用,这也很好。
nib
,在iOS5+中,如果队列中没有可重用的单元格,UITableView
会自动为您创建一个有效的单元格;因此指针永远不会是nil
,您不需要处理它。 - holex