Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 为什么[self.tableView reloadData]不起作用?_Iphone_Objective C_Ios_Uitableview - Fatal编程技术网

Iphone 为什么[self.tableView reloadData]不起作用?

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

这是cellforrowatinexpath:method的代码

- (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所说,在重新加载数据之前,请检查您的本地数据是否正在更新数据源