您的位置:首页 > 产品设计 > UI/UE

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的代理对象
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: