这是我在tableView:cellForRowAtIndexPath:方法中的代码,
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
// Configure the cell...
NSDictionary *temp = [self.placeArray objectAtIndex:[indexPath row]];
cell.textLabel.text = [temp objectForKey:@"name"];
cell.detailTextLabel.text = [[temp objectForKey:@"distance"] stringByAppendingString:@" km from Banglore"];
cell.imageView.image =[UIImage imageNamed:[temp objectForKey:@"category"]];
return cell;我有例外,
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 3 beyond bounds [0 .. 2]'有什么指示吗?
发布于 2013-10-29 08:23:25
看看你的Tableview代表是不是,
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.placeArray.count;
}否则让我知道..。
发布于 2013-10-29 08:33:24
异常本身为您提供了答案。您的self.placeArray只包含3个元素,并且您正在尝试创建多个单元格。您需要确保self.placeArray的计数在numberOfRowsInSection方法中返回,而且该数组在表视图重新加载时不会异步更新。
发布于 2013-10-30 18:33:11
在numberOfRowsForSection中返回的值大于placeArray中的对象数。
在线后
NSDictionary *temp = [self.placeArray objectAtIndex:[indexPath row]];加上这个
NSLog(@"number of places = %i", [placeArray count]);在该行处添加一个断点。您将看到应用程序在第四次命中此断点时会崩溃,因为numberOfRowsInSection返回>3行,而且您的placeArray只有<=3对象
https://stackoverflow.com/questions/19652990
复制相似问题