应用程序在删除UITableViewCell后会冻结

当我尝试删除请求的成功块中的UITableViewCell时,出现问题。

在我的

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath 

我正在做AFNetworking的请求

 - (NSURLSessionDataTask *)POST:(NSString *)URLString parameters:(id)parameters success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure 

之后,在成功块我通过closuresSVProgressHUD和删除单元更新UI:

 NSUserDefaults *usd = [NSUserDefaults standardUserDefaults]; [usd removeObjectForKey:@"payViaCreditCard"]; selectedCardID = nil; [[CreditCardManager sharedCreditCardManager] removeCreditCard:creditCardToDelete]; [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; [self.tableView reloadData]; 

最后,我的UI不更新,应用程序冻结,当我重新启动应用程序时,NSUserDefaults中的数据发生了变化。

如果您执行deleteRowsAtIndexPaths:withRowAnimationtableView reloadData那将会很好。

  [[CreditCardManager sharedCreditCardManager] removeCreditCard:creditCardToDelete]; [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; OR [[CreditCardManager sharedCreditCardManager] removeCreditCard:creditCardToDelete]; [self.tableView reloadData]; 

删除你应该使用的单元格

 - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewCellEditingStyleDelete; } - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { NSUserDefaults *usd = [NSUserDefaults standardUserDefaults]; [usd removeObjectForKey:@"payViaCreditCard"]; selectedCardID = nil; [[CreditCardManager sharedCreditCardManager] removeCreditCard:creditCardToDelete]; [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; //[self.tableView reloadData]; } } 
Interesting Posts