就是显示的条数比数据源的条数多一即可, 点击最后一个cell时, 添加更多的数据到数据源中。
显示List Num
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return ([self.dataController countOfList] + 1);
}
增加moreCell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//最后一行,点击显示更多
if ([indexPath row] == [self.dataController countOfList]) {
static NSString *moreCellIdentifier = @"loadMoreCell";
UITableViewCell *moreCell = [tableView dequeueReusableCellWithIdentifier:moreCellIdentifier];
if (moreCell == nil) {
moreCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:moreCellIdentifier];
moreCell.selectionStyle = UITableViewCellSelectionStyleNone;
}
[[moreCell textLabel] setText:@"点击显示更多"];
//textAlignment
[[moreCell textLabel] setTextAlignment:UITextAlignmentCenter];
return moreCell;
}
}
//点击时的处理
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//如果是点击更多
if (indexPath.row == [self.dataController countOfList]) {
//[self performSelectorInBackground:@selector(loadMore) withObject:nil];
//[loadMoreCell setHighlighted:NO];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
_pageNum = _pageNum + 1;
//取数据
[self.dataController prepareDataByKey:_keyWord keyType:_type pageSize:@"20" pageNum:[NSString stringWithFormat: @"%d", _pageNum]];
return;
}
}
//更新数据
[self.tableView reloadData];