私はにUITableView支えられていNSArrayます。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.data.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tv dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
}
id item = [self.data objectAtIndex:indexPath.row];
cell.item = item;
return cell;
}
非常に標準的です。ここで問題とreloadDataなるのは、同期的に要求しますがnumberOfSections、非同期numberOfRows的に呼び出すことcellForRowです。そのため、cellForRowAtIndexPath呼び出されるまでにデータ配列が変更さ[self.data objectAtIndex:indexPath.row]れ、範囲外の例外が発生してアプリがクラッシュすることがあります。これを回避するにはどうすればよいですか?
配列を設定するたびにdata、も呼び出すことに注意してください[self.tableView reloadData]。