- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == [items count]) {
UITableViewCell *loadMoreCell=[tableView cellForRowAtIndexPath:indexPath];
loadMoreCell.textLabel.text=@"loading more …";
[self performSelectorInBackground:@selector(loadMore) withObject:nil];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
return;
}
//其他cell的事件
}
-(void)loadMore
{
NSMutableArray *more;
more=[[NSMutableArray alloc] initWithCapacity:0];
for (int i=0; i<10; i++) {
[more addObject:[NSString stringWithFormat:@"cell ++%i",i]];
}
//加载你的数据
[self performSelectorOnMainThread:@selector(appendTableWith:) withObject:more waitUntilDone:NO];
[more release];
}
-(void) appendTableWith:(NSMutableArray *)data
{
for (int i=0;i<[data count];i++) {
[items addObject:[data objectAtIndex:i]];
}
NSMutableArray *insertIndexPaths = [NSMutableArray arrayWithCapacity:10];
for (int ind = 0; ind < [data count]; ind++) {
NSIndexPath *newPath = [NSIndexPath indexPathForRow:[items indexOfObject:[data objectAtIndex:ind]] inSection:0];
[insertIndexPaths addObject:newPath];
}
[self.myTableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation:UITableViewRowAnimationFade];
}