以下代码中dataArray是存储数据的数组,mainTableView是UITableView控件
1.在UITableView的最底部插入
-(void)loadTheLastCell { int lastIndex = [dataArray count]-1; if(lastIndex>=0) { NSIndexPath *path = [NSIndexPath indexPathForRow:lastIndex inSection:0]; NSArray* tArray = [NSArray arrayWithObject:path]; [mainTableView insertRowsAtIndexPaths:tArray withRowAnimation:UITableViewRowAnimationBottom]; } }
2.删除UITableView的数据
-(void) deleteData { NSRange tRange = NSMakeRange(0,2); [dataArray removeObjectsInRange:tRange]; NSIndexPath *path0 = [NSIndexPath indexPathForRow:0 inSection:0]; NSIndexPath *path1 = [NSIndexPath indexPathForRow:1 inSection:0]; NSArray* tArray = [NSArray arrayWithObjects:path0,path1,nil]; [mainTableView deleteRowsAtIndexPaths:tArray withRowAnimation:UITableViewRowAnimationBottom]; }
3.滚动到UITableView的最底部
-(void)delayScrollToBottom
{
int lastIndex = [dataArray count]-1;
if(lastIndex)
{
NSIndexPath *path = [NSIndexPath indexPathForRow:lastIndex inSection:0];
[mainTableView scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
}