【问题标题】:UIAlertController causes RowAnimation of a UITableViewCell-Deletion not to be calledUIAlertController 导致不调用 UITableViewCell-Deletion 的 RowAnimation
【发布时间】:2016-05-22 05:33:46
【问题描述】:

我尝试在用户删除信息之前集成警报。 没有动画,行删除是动画的并且工作正常。但在 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];

有什么建议可以让动画再次工作吗?

【问题讨论】:

    标签: ios objective-c uitableview animation uialertcontroller


    【解决方案1】:

    我认为 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];
    

    【讨论】:

    • 我试过了,但这不是导致问题的原因。点击删除后,tableview 更新,单元格消失,没有动画。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多