Iphone 为什么[self.tableView reloadData]不起作用?
这是cellforrowatinexpath:method的代码Iphone 为什么[self.tableView reloadData]不起作用?,iphone,objective-c,ios,uitableview,Iphone,Objective C,Ios,Uitableview,这是cellforrowatinexpath:method的代码 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier"; UITableViewCell *cell = [self.tableView dequ
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier];
if (cell == nil) { cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [array objectAtIndex:row];
return cell;
}
当我使用
[self.tableView reloadData]时代码>什么都没有发生?是否检查数据源和UITableView的委托?我认为数据源是nil或其他东西。尝试在单元格中为行设置一个断点,看看在调用reloadData时是否调用它。另外,请检查是否已经对填充单元格的数组进行了更改,并确保表视图已连接到其数据源和委托 您至少需要将该方法作为UITableViewDataSource协议的一部分来实现,并且tableView:cellForRowAtIndexPath:
(您已经实现了)。您还应该实现numberOfSectionsInTableView:
然后,您需要确保您的类实际用作数据源:
self.tableView.dataSource = self;
这需要通过Interface Builder或在awakeFromNib
或其他方法(如viewdiload:
now Q)中完成:该类是否属于UITableViewController子类?在调用[self.tableView reloadData]之前是否使用新值更新数组;好吧,我假设您为UITableView实现了dataSource和委托,您是否确保您的[self.tableView reloadData]已被调用?我假设视图出现时确实显示了一些内容。而且,正如Hanuman所说,在重新加载数据之前,请检查您的本地数据是否正在更新数据源