[英]Deleting rows in uitableview
我有一个应用程序,如果用户输入数据,行将使用该数据更新
我可以使用单个按钮说“删除”,单击该按钮会立即删除tableview中的所有行。
是的,你可以这么做。 首先从数据源中删除所有数据,然后重新加载表。 对于前者 -
[yourArrayDataSource removeAllObjects];
[yourTable reloadData];
要动态删除行 - 在IBAction
方法中执行此操作并将其链接到您的UIButton
。 只要按下按钮,您就会有一个流畅的动画效果,让您的所有行都淡出。
-(IBAction)deleteRows
{
[yourTable beginUpdates];
for(int i=0; i<[yourArrayDataSource count]; i++)
{
indexPath = [NSIndexPath indexPathForRow:i inSection:0];
[self.searchResTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
[yourTable endUpdates];
}
你可以在这里使用各种动画 -
UITableViewRowAnimationBottom
UITableViewRowAnimationFade
UITableViewRowAnimationMiddle
UITableViewRowAnimationNone
UITableViewRowAnimationRight
UITableViewRowAnimationTop
Srikar的回答让我走上正轨,但创造了许多额外的单项数组,并且调用deleteRowsAtIndexPaths远远超过了所需。
-(void)clearTable
{
NSMutableArray *indexPaths = [NSMutableArray array];
for(int i=0; i<[self.myArray count]; i++)
{
NSIndexPath *anIndexPath = [NSIndexPath indexPathForRow:i inSection:0];
[indexPaths addObject:anIndexPath];
}
[self.myTableView beginUpdates];
[self.myTableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
self.myArray = [NSArray array];
[self.myTableView endUpdates];
}
按下按钮操作方法
-(IBAction)deleteRows
{
[array removeAllObjects];
[tableview reloadData];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.