这篇文章是建立在
1.标记:指的是选中某一行,在这一行后面有个符号,常见的是对勾形式
通过修改cell的accessoryType属性来实现,首先,在ViewDidLoad中[tableView setEditing:NO animated:YES];表示把单元格可编辑状态这只为NO
当我们选中单元格的时候,调用此函数,首先是indexPath检测选中了哪一行,if判断当前单元格是否被标记,也就是当前单元格风格,是否为UITableViewCellAccessoryCheckmark风格,如果是,则换成UITableViewCellAccessoryNone(不被标记风格)风格,以下是accessoryType四个风格属性
UITableViewCellAccessoryCheckmark UITableViewCellAccessoryDetailDisclosureButton
UITableViewCellAccessoryDisclosureIndicator UITableViewCellAccessoryNone
2.移动
实现移动单元格就需要把单元格的编辑属性设置为YES,[tableView setEditing:YES animated:YES];
三种风格的分别是
UITableViewCellEditingStyleDelete UITableViewCellEditingStyleInsert
UITableViewCellEditingStyleNone
实现移动的方法
单元格的移动是选中单元格行后面三条横线才可以实现移动的
3.删除
首先是判断(UITableViewCellEditingStyle)editingStyle,所以
删除了张四 效果图:
4.添加
实现方法和删除方法相同,首先还是返回单元格编辑风格
为了显示效果明显,在.h文件中声明一个变量i
运行效果图:
在删除和添加单元格的用到UITableViewRowAnimation动画效果,它还有其他几种效果,在此不做测试
UITableViewRowAnimationAutomatic UITableViewRowAnimationTop
UITableViewRowAnimationBottom UITableViewRowAnimationLeft
UITableViewRowAnimationRight UITableViewRowAnimationMiddle
UITableViewRowAnimationFade UITableViewRowAnimationNone
本文转自新风作浪 51CTO博客,原文链接:http://blog.51cto.com/duxinfeng/1208744,如需转载请自行联系原作者