4.8 Enabling Swipe Deletion of Table View Cells
2013-11-28 10:38
337 查看
你是否曾经在tableView列表中删除某些行,你是怎么删除的呢?
通过点击某个按钮,然后列表每一行的左边出来一个红色减号,点击然后右边出来一个删除按钮,然后删除?(这种情况时设置列表的editing属性来实现的)
当然了,还有一种情况是在这一行上划一下,然后就出来一个删除按钮,这功能是怎么实现的呢?
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
-(void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];//苹果说这个一定要写,删了不知会咋样,小例子没出现问题
[_tableView setEditing:editing animated:animated];
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[tableRows removeObjectAtIndex:indexPath.row]; //先删除数据源里的数据,再从界面上删除
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
}
}
通过点击某个按钮,然后列表每一行的左边出来一个红色减号,点击然后右边出来一个删除按钮,然后删除?(这种情况时设置列表的editing属性来实现的)
当然了,还有一种情况是在这一行上划一下,然后就出来一个删除按钮,这功能是怎么实现的呢?
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
-(void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];//苹果说这个一定要写,删了不知会咋样,小例子没出现问题
[_tableView setEditing:editing animated:animated];
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[tableRows removeObjectAtIndex:indexPath.row]; //先删除数据源里的数据,再从界面上删除
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
}
}
相关文章推荐
- Dynamically size the height of the table view cells
- Table View Cells With Varying Row Heights
- iOS Quick Tip – programmatically hiding sections of a UITableView with static cells
- iOS 利用长按手势移动 Table View Cells
- 4.5 Using Different Types of Accessories in a Table View Cell
- 84.View the Exhibit and examine the structure of the EMPLOYEES table.
- 110.View the Exhibit and examine the structure of the CUSTOMERS table.
- how to iterate each tableview cells
- com.sun.pdfview.PDFParseException: Expected 'xref' at start of table
- WLCardViewLayout: Card and swipe out layout of CollectView.(可以滑动删除的卡片视图布局)
- Table View Programming Guide for iOS---(三)----Overview of the Table View API
- 利用长按手势移动 Table View Cells
- tableView numberOfRowsInSection:(NSInteger)section;不执行
- Local declaration of tableview hides instance variable 警告
- 100.View the Exhibit and examine the structure of the PROMOTIONS table.
- 159.View the Exhibit and examine the structure of the CUSTOMERS table.
- overview of the TableView API
- how to javafx hide background header of a tableview?
- 61.View the Exhibit and examine the structure of the PROMOTIONS table.
- 111.View the Exhibit and examine the structure of the CUSTOMERS table.