我的问题是相似的这家伙有什么:一个更细胞加入的tableView
Add a last cell to 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
条件?
为什么你还要在 “+1” 只使用
indexPath.row
代替rowN
的你的'numberOfRowsInSection'方法在那里?如果将if(rowN == [array count])更改为if(rowN> = [array count]),会发生什么? –@MichaelDautermann我相信他想在数组中的行之后添加一行,这就是+ 1 – akoso
@MichaelDautermann相同的结果。 :( –