码迷,mamicode.com
首页 > 其他好文 > 详细

UItableView-删除数据

时间:2014-07-09 17:07:00      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   数据   for   

一、UItableView 编辑模式 

#pragma mark 要设置代理, 实现代理协议

#pragma mark - 代理方法
#pragma mark 只要实现了这个方法,就会实现排序功能
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
    // 1. 取出移动行的模型数据
    Person *p = _persons[sourceIndexPath.row];
    
    // 2. 删除原来位置的模型数据
    [_persons removeObject:p];
    
    // 3. 把取出的模型数据插入新的位置
    [_persons insertObject:p atIndex:destinationIndexPath.row];
}


#pragma mark 当用户提交一个编制操作就会调用(比如点击“删除”按钮)等等
// 只要实现了这个方法,就会默认实现滑动删除功能
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    // 如果不是删除操作,直接返回
    if (editingStyle != UITableViewCellEditingStyleDelete) return;
    
    // 1. 删除模型数据
    [_persons removeObjectAtIndex:indexPath.row];
    
    // 2. 刷新数据
    [_tableview deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
}

#pragma mark - 删除
- (void)remove
{
    // 进入编制模式
    bool result = !_tableview.editing;
    [_tableview setEditing:result animated:YES];
}

 

UItableView-删除数据,布布扣,bubuko.com

UItableView-删除数据

标签:des   style   blog   color   数据   for   

原文地址:http://www.cnblogs.com/mdCode/p/3831900.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!