在动画块内,不建议使用reloadData方法,如果使用,会影响动画…
(即:要动画效果用beginUpdates, 不要动画效果用reloadData)
1.删除UITableView的一行时
// 删除"我的收藏"彩印的网络请求- (void)deleteMyFavorCaiyin:(MyFavorCell *)cell{ DeleteFavorCaiyinService *service = [[DeleteFavorCaiyinService alloc] init]; [servicedeleteMyFavorCaiyin:cell.myFavorCaiyinModelsuccess:^(BOOL success) {if(success) { DEBUGLog(@"成功");// 1.更新数据NSIndexPath *indexPath = [_myFavorTableViewindexPathForCell:cell]; [_myFavorCaiyinModelsremoveObjectAtIndex:indexPath.row];// 2.更新UI (代替了reloadData方法)// [_myFavorTableView reloadData];[_myFavorTableView beginUpdates];// 动画效果[_myFavorTableViewdeleteRowsAtIndexPaths:[NSArrayarrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationFade]; [_myFavorTableView endUpdates];// 3.弹出提示"删除成功&失败"的菊花[selfshowDeleteHUDWithSuccess:YES]; }else{ DEBUGLog(@"失败");// 弹出提示"删除成功&失败"的菊花[selfshowDeleteHUDWithSuccess:NO]; } }];}
2.添加UITableView的一行时
// SVPullToRefresh官方代码(上拉加载更多)- (void)insertRowAtBottom { __weak SVViewController *weakSelf = self;int64_tdelayInSeconds =2.0;dispatch_time_tpopTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC); dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ [weakSelf.tableView beginUpdates];//我觉得这句话写在下面更合理// 1.更新数据[weakSelf.dataSource addObject:[weakSelf.dataSource.lastObject dateByAddingTimeInterval:-90]];// 动画效果[weakSelf.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:weakSelf.dataSource.count-1inSection:0]] withRowAnimation:UITableViewRowAnimationTop];// 2.更新UI (代替了reloadData方法)[weakSelf.tableView endUpdates];// 3.停止菊花[weakSelf.tableView.infiniteScrollingView stopAnimating]; }); }