我有一张桌子,可能有几百行,都有不同的高度。每当用户删除一行,呼叫:TableView deleteRowsAtIndexPaths:withRowAnimation非常慢
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
需要很长时间才能执行(大约2.5s)。
有没有其他的电话或这种方式来加速?谢谢!
我有一张桌子,可能有几百行,都有不同的高度。每当用户删除一行,呼叫:TableView deleteRowsAtIndexPaths:withRowAnimation非常慢
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
需要很长时间才能执行(大约2.5s)。
有没有其他的电话或这种方式来加速?谢谢!
使用UITableView
的方法estimatedRowHeight
加快速度。
提供行高度的非负估计可以提高加载表视图的性能。如果表格包含可变高度的行,则在表格加载时计算其所有高度可能会很昂贵。使用估算功能可以将几何计算的成本从加载时间推迟到滚动时间。
在任何情况下,您都应该使用Instruments来测量哪些代码部分占用了大部分时间。
你可以试试这个。它有点不道德,但它像一个魅力。
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if([textArray count]>0){
[self deleteRowAtIndexPath:indexPath.row];
} //method fired when u select a row, which calls a method
}
-(void)deleteRowAtIndexPath:(int) indexPath{ //this method removes the data in the array from which the tableview is being populated
[textArray removeObjectAtIndex:indexPath];
[self.tableView reloadData]; //after deleting the data from the array it reloads the tableview
}
textArray是一个NSMutableArray,从中填充tableview。
但是这个dsnt有任何动画。
这个方法也会调用一些数据源委托的方法,我想这就是它被卡住的地方,你能告诉你如何实现'UITableView'的数据源委托吗? – KudoCC 2014-09-05 09:41:04
一定要在主线程上调用它 – Andrea 2014-09-05 09:43:31