·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> app软件开发 >> IOS开发 >> UITableView删除行和行排序这里只介绍代理方法

UITableView删除行和行排序这里只介绍代理方法

作者:佚名      IOS开发编辑:admin      更新时间:2022-07-23

#PRagma mark -代理方法

#pragma mark 设置cell表格高度

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 60;

}

#pragma mark 当cell实行编辑功能时调用

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{

    

    if(editingStyle!=UITableViewCellEditingStyleDelete) return;

    //1.删除数据源数据

    [_persons removeObject:_persons[indexPath.row]];

    //2.重新加载数据

   [self.tableView reloadData];

   

}

#pragma mark 当cell实行排序功能时调用

-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{

    

    

    //1 拿出要移动的数据,并删除

    Person *p=_persons[sourceIndexPath.row];

    

    [_persons removeObject:p];

    

    

    //2 把要移动的数据添加到目的位置

    

    [_persons insertObject:p atIndex:destinationIndexPath.row];

    

}

 

 

 

#pragma mark 监听删除按钮

- (IBAction)remove:(UIBarButtonItem *)sender {

    

//     self.tableView.editing=YES;//进入编辑模式

    

    BOOL result=!self.tableView.isEditing;

    

    [self.tableView setEditing:result animated:YES];

    

    

}