你偶然删除了背景色和分隔符样式吗?如果你这样做了,这就是为什么没有额外的细胞。我认为默认的uiTableView不会添加更多的单元格,它只是具有分隔符样式来创建这种错觉,因为它有白色背景,所以它们看起来像单元格。
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}
如果不是这样,您可以尝试添加无法选择的额外单元格:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return ([source count] <= 7) ? 7 : [source count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Set all labels to be blank
if([source count] <= 7 && indexPath.row > [source count]) {
cell.textLabel.text = @"";
cell.selectionStyle = UITableViewCellSelectionStyleNone;
} else {
cell.textLabel.text = [source objectAtIndex:indexPath.row];
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
}
return cell;
}