Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS应用程序在显示UIAlertController时崩溃_Ios_Swift_Uiview_Uialertcontroller_Visitor - Fatal编程技术网

iOS应用程序在显示UIAlertController时崩溃

iOS应用程序在显示UIAlertController时崩溃,ios,swift,uiview,uialertcontroller,visitor,Ios,Swift,Uiview,Uialertcontroller,Visitor,当我尝试在我的ViewController上显示UIAlertController时,我获得了线程1:EXC\u BAD\u访问权限 这是我的代码: let controller = UIAlertController(title: "bob", message: nil, preferredStyle: .actionSheet) let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil) co

当我尝试在我的ViewController上显示
UIAlertController
时,我获得了
线程1:EXC\u BAD\u访问权限

这是我的代码:

let controller = UIAlertController(title: "bob", message: nil, preferredStyle: .actionSheet)
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
controller.addAction(cancelAction)
DispatchQueue.main.async {
    self.present(controller, animated: false, completion: nil)
}
我还尝试用一个空白的
UIViewController()
替换
UIAlertController
,我得到了一个非常相似的堆栈跟踪,其中崩溃发生在同一位置

这是堆栈跟踪

#0  0x00007fff2b13578d in CA::Layer::retain_parent(CA::Transaction*) const ()
#1  0x00007fff2b1455b9 in CALayerGetSuperlayer ()
#2  0x00007fff485813a8 in -[UIView(UIKitManual) superview] ()
#3  0x00007fff485bf1aa in -[_UITintColorVisitor _visitView:] ()
#4  0x00007fff485beb1f in _UIViewVisitorRecursivelyEntertainDescendingVisitors ()
#5  0x00007fff485bec06 in _UIViewVisitorRecursivelyEntertainDescendingVisitors ()
#6  0x00007fff485bec06 in _UIViewVisitorRecursivelyEntertainDescendingVisitors ()
#7  0x00007fff485bec06 in _UIViewVisitorRecursivelyEntertainDescendingVisitors ()
#8  0x00007fff485bec06 in _UIViewVisitorRecursivelyEntertainDescendingVisitors ()
#9  0x00007fff485bec06 in _UIViewVisitorRecursivelyEntertainDescendingVisitors ()
#10 0x00007fff485bec06 in _UIViewVisitorRecursivelyEntertainDescendingVisitors ()
#11 0x00007fff485bec06 in _UIViewVisitorRecursivelyEntertainDescendingVisitors ()
#12 0x00007fff485bec06 in _UIViewVisitorRecursivelyEntertainDescendingVisitors ()
#13 0x00007fff485bec06 in _UIViewVisitorRecursivelyEntertainDescendingVisitors ()
#14 0x00007fff485bec06 in _UIViewVisitorRecursivelyEntertainDescendingVisitors ()
#15 0x00007fff485bec06 in _UIViewVisitorRecursivelyEntertainDescendingVisitors ()
#16 0x00007fff485bec06 in _UIViewVisitorRecursivelyEntertainDescendingVisitors ()
#17 0x00007fff485be6d2 in +[_UIViewVisitor _startTraversalOfVisitor:withView:] ()
#18 0x00007fff4854d9db in -[UIView _dispatchTintColorVisitorWithReasons:] ()
#19 0x00007fff4792522a in -[UIPresentationController _enableOcclusion:] ()
#20 0x00007fff47a42124 in -[_UIViewControllerTransitionCoordinator _applyBlocks:releaseBlocks:] ()
#21 0x00007fff47a3e446 in -[_UIViewControllerTransitionContext __runAlongsideAnimations] ()
#22 0x00007fff4856a44f in __63+[UIView(Animation) _setAlongsideAnimations:toRunByEndOfBlock:]_block_invoke ()
#23 0x00007fff4853b7c0 in -[UIViewAnimationState _runAlongsideAnimations] ()
#24 0x00007fff4853a50a in -[UIViewAnimationState pop] ()
#25 0x00007fff485378ce in +[UIViewAnimationState popAnimationState] ()
#26 0x00007fff4856be60 in +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] ()
#27 0x00007fff4856c231 in +[UIView(UIViewAnimationWithBlocks) animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:] ()
#28 0x00007fff4763b3a3 in -[UIAlertControllerVisualStyleActionSheet animateAlertControllerView:ofAlertController:forPresentation:inContainerView:descendantOfContainerView:duration:completionBlock:] ()
#29 0x00007fff47627ac3 in -[_UIAlertControllerAnimatedTransitioning _animateTransition:completionBlock:] ()
#30 0x00007fff4762748f in -[_UIAlertControllerAnimatedTransitioning animateTransition:] ()
#31 0x00007fff47a42cf5 in ___UIViewControllerTransitioningRunCustomTransition_block_invoke_2 ()
#32 0x00007fff47b5af7e in +[UIInputResponderController _pinInputViewsForInputResponderController:onBehalfOfResponder:duringBlock:] ()
#33 0x00007fff47a42c89 in ___UIViewControllerTransitioningRunCustomTransition_block_invoke.645 ()
#34 0x00007fff4856a351 in +[UIView(Animation) _setAlongsideAnimations:toRunByEndOfBlock:] ()
#35 0x00007fff47a42b0f in _UIViewControllerTransitioningRunCustomTransition ()
#36 0x00007fff47924740 in __56-[UIPresentationController runTransitionForCurrentState]_block_invoke.465 ()
#37 0x00007fff4809be5b in _runAfterCACommitDeferredBlocks ()
#38 0x00007fff4808c7b4 in _cleanUpAfterCAFlushAndRunDeferredBlocks ()
#39 0x00007fff480bc3a9 in _afterCACommitHandler ()
#40 0x00007fff23bd3867 in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ ()
#41 0x00007fff23bce2fe in __CFRunLoopDoObservers ()
#42 0x00007fff23bce97a in __CFRunLoopRun ()
#43 0x00007fff23bce066 in CFRunLoopRunSpecific ()
#44 0x00007fff384c0bb0 in GSEventRunModal ()
#45 0x00007fff48092d4d in UIApplicationMain ()
#46 0x000000010c50ca8b in main at /Users/stephenfurlani/Developer/winterfell/Winterfell/AppDelegate.swift:21
#47 0x00007fff5227ec25 in start ()
我不知道发生了什么事
UIAlertController
在我的应用程序中的其他位置工作正常。它在我的iPhone 11 Pro Max 13.1.3上崩溃,但在我的iPhone 11 13.1.3上运行良好。如果我在
async{}
块的主线程上运行所有内容,它就会崩溃

我还将注意到,它在iPhone11Pro Max的模拟器上崩溃,但在iPhone11的模拟器上却没有

我的VC层次结构如下所示:

TabBar-tab->Navigation-root->TableView-show->DetailView

详细视图显示的是
UIAlertController

TabBar-tab->Navigation-root->TableView-show->DetailView-show->SubDetailView

如上图所示,我可以从子详细信息页面显示AlertController


我试图创建一个小项目来突出显示错误,但效果很好。X(


这些问题的答案都没有帮助:
*
*

*

您编写的代码在iphone上运行良好,但在iPad上,操作表的外观与iphone不一样。它出现在您点击的UI元素中。因此,操作表在iPad上运行

       let controller = UIAlertController(title: "bob", message: nil, preferredStyle: .actionSheet)
      let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
      controller.addAction(cancelAction)
  if let presenter = controller.popoverPresentationController {
          // From Bar Button
       presenter.barButtonItem = yourBarButtonItem
  // Comment the above line if you are tapping on some UIElement other than barButton
          presenter.sourceView = yourUIView
     presenter.sourceRect = yourUIView.bounds
  }

      DispatchQueue.main.async {
          self.present(controller, animated: false, completion: nil)
      }

这是在iPad上吗?@MojtabaHosseini不,不是。我在问题中添加了这一评论,但它在iPhone 11上有效,但在iPhone 11 Pro Max上崩溃。只是出于好奇,如果你将所有四行代码都包装在
async
闭包中会怎么样?@JoshuaKaden它仍然崩溃:(你能创建一个非常小的github项目来复制崩溃吗?显然这与你共享的小代码无关。这不是在iPad上运行的。它是在iPhone 11 Pro Max上崩溃的。我已经在问题中发布了我尝试解决iPad问题的方法。它仍然崩溃。