代码改变世界

IOS tableView删除数据

2015-07-21 14:39  一树一菩提  阅读(575)  评论(0编辑  收藏  举报

    NSMutableArray *_allshops;

    NSMutableArray *_deleteshops;

 

-(IBAction)remove{

    

   1. //记录删除的行号

    //创建动态数组存放行号的集合

    NSMutableArray *deletepath = [NSMutableArray array];

    //遍历存放删除数据的数组,把行号放到deletepath中

    for (Shop * s in _deleteshops) {

       int row = [_deleteshops indexOfObject:s];

        NSIndexPath *path = [NSIndexPath indexPathForRow:row inSection:0];

        [deletepath addObject:path];

    }

    

    //从选中的数组中删除数据

    [_allshops removeObjectsInArray:_deleteshops];

    

  //选中的行删除加载

    [self.tableView deleteRowsAtIndexPaths:deletepath withRowAnimation:UITableViewRowAnimationTop];

   2. //全部重新加载

//    [self.tableView reloadData];

  

    

    //清空deleteshops中的数据

    [_deleteshops removeAllObjects];

    //删除完毕,垃圾桶灰掉

    _removeItem.enabled = NO;

    //修改标题

    _titleLabel.text = @"淘宝";

    

 

    NSLog(@"----删除数据");

 

 

}