UI基础整理-10
2015-12-02 20:51
302 查看
UITableView编辑
编辑:
//1.让tableView进入编辑状态
- (void)deleteDataAction:(UIBarButtonItem *)barButton{ }
//2.设置可编辑区域
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{ }
//3.设定编辑样式(删除或者添加)
- (UITableViewCellEditingStyle )tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ }
//4.完成编辑(操作UI之前要先操作数据,所有的编辑都是先编辑数据)
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ }
移动:
//1.让tableView进入编辑状态
- (void)moveDataAction:(UIBarButtonItem *)barButton{ }
//2.指定哪些可以移动
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{ }
//3.完成移动
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{
//获取源分区数组
NSMutableArray *array = self.dataDict[self.group[sourceIndexPath.section]];
//找到对应的对象(要移动的元素)
self.student = array[sourceIndexPath.row];
//从原位置移除(同一分区的情况下在同一数组操作)
[array removeObject:_student];//相同的会全部移除
//添加到新位置(同一分区的情况下在同一数组操作)
[array insertObject:_student atIndex:destinationIndexPath.row];
//进行数据交换
}
//补充:限制是否可以跨区移动
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath{
//如果源分区和目的分区是同一个地方,那么可以返回目的地点作为移动结果
if(sourceIndexPath.section == proposedDestinationIndexPath.section){
return proposedDestinationIndexPath;
}
//否则,滚回老家
return sourceIndexPath;
}
UITableViewController
//1.UITableViewController是UIViewController的子类,所有父类的特性均可以使用,但它具备独有的初始化方法
//2.self.view和self.tableView是同一个对象,但一般情况下我们使用self.tableView,原因是我们必须保证消息可以正确发送(子类扩充了父类)
//3.UITableViewController默认遵循了UITableViewDelegate和UITableViewDataSource,并且把自己设置为了self.tableView的代理对象
编辑:
//1.让tableView进入编辑状态
- (void)deleteDataAction:(UIBarButtonItem *)barButton{ }
//2.设置可编辑区域
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{ }
//3.设定编辑样式(删除或者添加)
- (UITableViewCellEditingStyle )tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ }
//4.完成编辑(操作UI之前要先操作数据,所有的编辑都是先编辑数据)
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ }
移动:
//1.让tableView进入编辑状态
- (void)moveDataAction:(UIBarButtonItem *)barButton{ }
//2.指定哪些可以移动
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{ }
//3.完成移动
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{
//获取源分区数组
NSMutableArray *array = self.dataDict[self.group[sourceIndexPath.section]];
//找到对应的对象(要移动的元素)
self.student = array[sourceIndexPath.row];
//从原位置移除(同一分区的情况下在同一数组操作)
[array removeObject:_student];//相同的会全部移除
//添加到新位置(同一分区的情况下在同一数组操作)
[array insertObject:_student atIndex:destinationIndexPath.row];
//进行数据交换
}
//补充:限制是否可以跨区移动
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath{
//如果源分区和目的分区是同一个地方,那么可以返回目的地点作为移动结果
if(sourceIndexPath.section == proposedDestinationIndexPath.section){
return proposedDestinationIndexPath;
}
//否则,滚回老家
return sourceIndexPath;
}
UITableViewController
//1.UITableViewController是UIViewController的子类,所有父类的特性均可以使用,但它具备独有的初始化方法
//2.self.view和self.tableView是同一个对象,但一般情况下我们使用self.tableView,原因是我们必须保证消息可以正确发送(子类扩充了父类)
//3.UITableViewController默认遵循了UITableViewDelegate和UITableViewDataSource,并且把自己设置为了self.tableView的代理对象
相关文章推荐
- UIControl整理笔记
- UI基础整理-9
- 【android_温故知新】第 1 组 UI 组件:布局管理器
- UI基础整理-8
- 爬爬爬之路:UI(十三) 数据解析
- UI基础整理-7
- UITextView - 4
- 新找到的一款字体 fantasque-sans-mono
- 如何利用QT设计师设计的ui生成相应头文件
- UIPickView 和 UIDatePicker
- UI基础整理-6
- Volley上传文件
- UI基础整理-5
- UI基础整理-4
- 13、UIKit Dynamics学习
- UE4 Particle Instance Parameters Tutorial
- Android进程和线程 --消息队列模型 (Looper, MessageQueue, Handler) (1)
- view 中的 opaque , alpha , 和 alpha 的区别
- POJ2299 Ultra-QuickSort 归并排序和逆序数,树状数组
- 【HDU 1005】Number Sequence