12 UITableView编辑和移动 、UITableViewController、(+UIDatePicker)
2015-12-18 20:29
471 查看
1、UITableView编辑
tableView的编辑:cell的添加、删除。使用场景:
删除一个下载好的视频,删除联系人;
插入一条新的聊天记录等
编辑步骤:
1、让tableView处于编辑状态
TableView方法
- (void)setEditing:(BOOL)editing animated:(BOOL)animated;
2、指定tableView哪些行可以编辑
TableView DataSource方法
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;
3、指定tableView编辑的样式(添加、删除)
TableView Delegate方法
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;
4、编辑完成(先操作数据源,再修改UI)
TableView DataSource方法
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;
2、UITableView移动
移动步骤:1、让tableView处于编辑状态
TableView方法
- (void)setEditing:(BOOL)editing animated:(BOOL)animated;
2、指定tableView哪些行可以移动
TableView DataSource方法
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;
3、移动完成
TableView DataSource方法
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
4、监测移动过程,实现限制跨区移动
TableView方法
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
3、UITableViewController
UITableViewController继承自UIViewController,自带一个tableViewself.view不是UIView而是UITableView
datasource和delegate默认都是self(UITableViewController)
开发中只需要建立UITableViewController子类
4、UIDatePicker
见代码总结
无论编辑还是移动,都先让tableView进入编辑状态。编辑结束或者移动结束,要先修改数组或字典中的数据,在更改UI。
UITableViewController是封装好了各种delegate和datasource,能提高我们开发速度。
相关文章推荐
- 11 UITableView表视图
- UIPickerView
- UIStoryboard和UIResponder
- UIImageView和UIImage
- 10 导航控制器UINavigationController、导航条navigationBar、界面通信(属性传值、代理传值、单例传值)
- UIAlertView与UIActionSheet
- 09 UIScrollView 、 UIPageControl
- 08-2 UISwitch and UIStepper
- IOS 开发学习笔记-基础 UI(十)九宫格布局,块动画,字典转模型,Xib使用
- 08-1 UIControl 及其子类 UISegmentedControl 、UISlider
- UIScrollView的使用
- 07 手势识别器、UIImageView、(transform)、模拟button内部实现触摸事件
- UILabel的使用
- 有关OpenCV1.0中GUI命令的几个函数学习总结
- UITextField的使用
- UIScreen,UIFont,UIColor,UIView,UIButton等总结
- Java中serialVersionUID的解释
- Java中的SerialVersionUID
- 关于Serializable的serialVersionUID
- UVALive-3972 March of the Penguins (最大流:节点容量)