UIAlertController导致不调用UITableViewCell-Deletion的RowAnimation

时间:2016-05-22 05:33:47

标签: ios objective-c uitableview animation uialertcontroller

我尝试在用户删除信息之前集成警报。 没有动画,行删除动画并且工作正常。但是在UIAlertAction处理程序中,动画不再有效:

  UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil
                                                                   message:@"Are you sure you want to delete the Inforamtion?"
                                                            preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction* deleteAction = [UIAlertAction actionWithTitle:@"Delete" style:UIAlertActionStyleDestructive
                                                          handler:^(UIAlertAction * action) {

                                                              // Find the cell taped Item using the position  of the sender as located at relative to the tableview
                                                              CGPoint buttonPosition = [deleteTapped convertPoint:CGPointZero toView:self.tableView];
                                                              NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];

                                                              // Update the data model
                                                              [self.checkout.paymentMethods removeObjectAtIndex:(indexPath.row -1)];

                                                              // Delete the row from the tableview
                                                              [self.tableView beginUpdates];
                                                              [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:(UITableViewRowAnimationFade)];
                                                              [self.tableView endUpdates];


                                                          }];

    [alert addAction:deleteAction];

    UIAlertAction* keepAction = [UIAlertAction actionWithTitle:@"Keep" style:UIAlertActionStyleDefault
                                                         handler:^(UIAlertAction * action) {

                                                         }];



 [alert addAction:keepAction];

 [self presentViewController:alert animated:YES completion:nil];

有关如何让动画再次运作的任何建议吗?

1 个答案:

答案 0 :(得分:0)

我认为begin和endUpdate调用导致了问题。请罗马他们应该工作。

使用这种方式:

UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil
                                                                   message:@"Are you sure you want to delete the Inforamtion?"
                                                            preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction* deleteAction = [UIAlertAction actionWithTitle:@"Delete" style:UIAlertActionStyleDestructive
                                                          handler:^(UIAlertAction * action) {

                                                              // Find the cell taped Item using the position  of the sender as located at relative to the tableview
                                                              CGPoint buttonPosition = [deleteTapped convertPoint:CGPointZero toView:self.tableView];
                                                              NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:buttonPosition];

                                                              // Update the data model
                                                              [self.checkout.paymentMethods removeObjectAtIndex:(indexPath.row -1)];

                                                              // Delete the row from the tableview
                                                              [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];


                                                          }];

    [alert addAction:deleteAction];

    UIAlertAction* keepAction = [UIAlertAction actionWithTitle:@"Keep" style:UIAlertActionStyleDefault
                                                         handler:^(UIAlertAction * action) {

                                                         }];



 [alert addAction:keepAction];