当我尝试在请求的成功块中删除 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
之后在成功阻止我通过解雇SVProgressHUD
并删除单元格来更新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中的数据发生了变化。
答案 0 :(得分:2)
如果您执行deleteRowsAtIndexPaths:withRowAnimation
或tableView reloadData
,那就太好了。
[[CreditCardManager sharedCreditCardManager] removeCreditCard:creditCardToDelete];
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
OR
[[CreditCardManager sharedCreditCardManager] removeCreditCard:creditCardToDelete];
[self.tableView reloadData];
答案 1 :(得分:0)
要删除单元格,您应该使用
- (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];
}
}