我使用UiTableView显示数据库中的一些数据。代码是,
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
// Configure the cell...
NSInteger uniqueId = [self.database.arrayColumnNames indexOfObject:@"id"];
NSInteger title = [self.database.arrayColumnNames indexOfObject:@"title"];
NSInteger Name = [self.database.arrayColumnNames indexOfObject:@"Name"];
NSInteger picture = [self.database.arrayColumnNames indexOfObject:@"pictureName"];//3
cell.textLabel.text = [NSString stringWithFormat:@"%@: %@",[[self.arrayInfo objectAtIndex:indexPath.row] objectAtIndex:uniqueId], [[self.arrayInfo objectAtIndex:indexPath.row] objectAtIndex:title]];
cell.imageView.image = [UIImage imageNamed:[[self.arrayInfo objectAtIndex:indexPath.row] objectAtIndex:picture]];
cell.detailTextLabel.text = [NSString stringWithFormat:@" %@", [[self.arrayInfo objectAtIndex:indexPath.row] objectAtIndex:bandName]];
return cell;
}
在我运行代码之后,我收到了一个错误,
-[__NSArrayM objectAtIndex:]: index 3 beyond bounds [0 .. 2]
我在这个方法中添加了一些断点,看起来indexPath的长度是2,图片的NSInteger是3,所以发生了错误。这是我对这个错误的想法,但我不知道如何解决它。