两种局部刷新UITableView的方法的使用条件

时间:2014-07-22 22:59:54   收藏:0   阅读:216

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

  //1.取消选中这一行

  [tableView deselectRowAtIndexPath:indexPath animated:YES];

  //2.获取当前选中的数据

  Shop *shop = _shops[indexPath.row];

  //3.控制当前cell是否被选中

  if( [_deleteShops containsObject:shop] ){

    //如果之前已选中,现在取消选中

    [_deleteShops removeObject:shop];

  }else{

    //如果之前已取消选中,则现在选中

    [_deleteShops addObject:shop];

  }

  //4.刷新表格(1.此局部刷新方法的使用条件:在tableView总数量不变的情况下,才能用它进行局部刷新)

  [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationMiddle];

  //(2.此局部刷新方法的使用条件:调用此方法删除多少行数据,tableView也要删除相同数量的数据)

  [tableView deleteRowsAtIndexPaths:[indexPath] withRowAnimation:UITableViewRowAnimationTop];

}

两种局部刷新UITableView的方法的使用条件,码迷,mamicode.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!