ios UITableView多选删除

第一步,

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {     
    return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
} 
UITableViewCellEditingStyleDelete是出现红的减号,再点一下就出来划动时出现的删除钮;UITableViewCellEditingStyleInsert是出现红的加号应该是插入数据的时候用的吧,没细研究,最神奇的是两个同时出现就出现了前面带圈的多选项.
 
第二步,调出前面带圈的多选项.其实就是调用[self.tableview setEditing:YES animated:YES]啦,隐藏的话就setEditing:NO
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {     
    if (rightButton.title== @"确定") {        
        [deleteDic setObject:indexPath forKey:[dataArray objectAtIndex:indexPath.row]];              
    }     
    else 
    {              
    } 
}  

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{     
    if (rightButton.title == @"确定") {         
       [deleteDic removeObjectForKey:[dataArray objectAtIndex:indexPath.row]];     
    }      
} 
一个是多选状态下添加刚选择的项,一下移除刚取消的项.哎,真复杂.
第四步,得到想删除的项了,处理一下呗
[dataArray removeObjectsInArray:[deleteDic allKeys]];
 [self.tableview deleteRowsAtIndexPaths:[NSArray arrayWithArray:[deleteDic allValues]] withRowAnimation:UITableViewRowAnimationFade];
 [deleteDic removeAllObjects]; 
好啦,搞定,看一下效果图.

首先得到一个列表.

点击编辑,出现选择框.

选择想要删除的项.
 

点删除.

删除以后的效果.
 
具体代码见附件.

 相关文章:

<<UITableView划动删除的实现>>

本文出自 “rainbird” 博客,请务必保留此出处http://rainbird.blog.51cto.com/211214/636270

posted on 2013-09-29 16:17  Hai_阔天空  阅读(571)  评论(0)    收藏  举报

导航