UI基础整理-10

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 的代理对象








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值