ios - @escaping @callee_guaranteed (@guaranteed UIAlertAction) -> ()

标签 ios swift uialertcontroller thunk

我在实时应用程序中发生了崩溃,我无法在开发过程中重现它。日志来自 Crashlytics。

我无法弄清楚崩溃的原因以及如何修复。

有什么帮助吗?

崩溃日志

Crashed: com.apple.main-thread
0  MyApp                          0x100f5d538 closure #2 in MyViewController.buttonTapped(_:) + 4308292920 (<compiler-generated>:4308292920)
1  MyApp                          0x101250a98 thunk for @escaping @callee_guaranteed (@guaranteed UIAlertAction) -> () + 4311386776 (<compiler-generated>:4311386776)
2  UIKitCore                      0x19cb4aed0 -[UIAlertController _invokeHandlersForAction:] + 108
3  UIKitCore                      0x19cb4b82c __103-[UIAlertController _dismissAnimated:triggeringAction:triggeredByPopoverDimmingView:dismissCompletion:]_block_invoke.458 + 28
4  UIKitCore                      0x19cdfcfe0 -[UIPresentationController transitionDidFinish:] + 952
5  UIKitCore                      0x19ce0176c __56-[UIPresentationController runTransitionForCurrentState]_block_invoke.503 + 208
6  UIKitCore                      0x19cf055a8 -[_UIViewControllerTransitionContext completeTransition:] + 100
7  UIKitCore                      0x19d981d90 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 588
8  UIKitCore                      0x19d955c70 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 244
9  UIKitCore                      0x19d956178 -[UIViewAnimationState animationDidStop:finished:] + 240
10 UIKitCore                      0x19d9562c8 -[UIViewAnimationState animationDidStop:finished:] + 576
11 QuartzCore                     0x19ff07dac CA::Layer::run_animation_callbacks(void*) + 276
12 libdispatch.dylib              0x19913f184 _dispatch_client_callout + 16
13 libdispatch.dylib              0x1990f1190 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1044
14 CoreFoundation                 0x1993f05e4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
15 CoreFoundation                 0x1993eb5d8 __CFRunLoopRun + 2004
16 CoreFoundation                 0x1993eaadc CFRunLoopRunSpecific + 464
17 GraphicsServices               0x1a338b328 GSEventRunModal + 104
18 UIKitCore                      0x19d4f863c UIApplicationMain + 1936
19 MyApp                          0x100f24840 main + 21 (ProfileViewController.swift:21)
20 libdyld.dylib                  0x199274360 start + 4

MyViewController.swift
@IBAction func buttonTapped(_ sender: UIButton) {

    let alert = UIAlertController(title: "Delete", message: "", preferredStyle: .alert)

    let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertAction.Style.cancel) { (action) in
        return
    }

    let deleteAction = UIAlertAction(title: "Delete", style: UIAlertAction.Style.default) { (action) in
        let indexPathRow = sender.tag

        guard indexPathRow >= 0 else {
            return
        }

        guard let id = self.dataSource[indexPathRow].id else {
            return
        }
        self.delete(id: id)
    }

    alert.addAction(cancelAction)
    alert.addAction(deleteAction)

    DispatchQueue.main.async {
        self.present(alert, animated: true, completion: nil)
    }
}

最佳答案

尝试以下

@IBAction func buttonTapped(_ sender: UIButton) {

    let alert = UIAlertController(title: "Delete", message: "", preferredStyle: .alert)

    let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertAction.Style.cancel) { (action) in
        return
    }

    // prepare data on stack call
    let indexPathRow = sender.tag
    guard indexPathRow >= 0 else { return }
    guard let id = self.dataSource[indexPathRow].id else { return }

    let deleteAction = UIAlertAction(title: "Delete", 
            style: UIAlertAction.Style.default) { [weak self] (action) in
        self?.delete(id: id)
    }

    alert.addAction(cancelAction)
    alert.addAction(deleteAction)

    DispatchQueue.main.async { [weak self] in
        self?.present(alert, animated: true, completion: nil)
    }
}

关于ios - @escaping @callee_guaranteed (@guaranteed UIAlertAction) -> (),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61429415/

相关文章:

objective-c - 改变位置 UIAlertController (UIAlertControllerStyleActionSheet)

iphone - Xcode 4 : My iPhone projects have become Mac OS projects. 。我无法改变这个

objective-c - "Weighted"随机数发生器

ios - 在 xcode 8 中从 swift 2.2 迁移到 swift 3.0

ios - 将字节数组转换为 UIImage

ios - 从 NSMutableDictionary 转换?到不相关的类型 [AnyHashble :Any] always fails

ios - 禁用 UIAlertController 框架外的触摸以取消

ios - UITableViewDelegate 无法工作并出现错误( fatal error : Unexpectedly found nil while unwrapping an Optional value in UITableView in swift 4)

ios - 如何在具有多个部分的 TableView 中使用 searchBar?

ios - UIAlertController 操作表在第二次调用时没有响应