Моя проблема похожа на то, что было у этого парня:
Добавить последнюю ячейку в UItableview
На самом деле я использую тот же метод, который был выбран в этомвопрос, вот фрагмент кода:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [array count] + 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
// cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
}
// Configure the cell.
NSUInteger rowN = [indexPath row];
if (rowN == [array count]) {
cell.textLabel.text = [NSString stringWithFormat:@"Some Text"];
} else {
TFHppleElement* pCell = [array objectAtIndex:indexPath.row];
cell.textLabel.text = [NSString stringWithFormat:@"%@", [pCell content]];
}
return cell;
}
Теперь я получаю сообщение об ошибке исключения: *** -[__NSArrayM objectAtIndex:]: index 6 beyond bounds [0 .. 5]
.
В чем может быть проблема?Из ошибки похоже, что [array objectAtIndex:indexPath.row]
пытается получить доступ к 6-му индексу массива, который не существует, но почему он пытается получить доступ к 6-му индексу, когда у меня есть код в состоянии else
?