无法关闭 ViewControllerAnimated iOS 9.3
Unable to dismissViewControllerAnimated iOS 9.3
我正在展示一个 UIAlertController
,而在 UIAlertAction
我正在关闭视图控制器。在 iOS 9.3 之前它工作正常。但在 iOS 9.3 中它不起作用。以下是代码。
let alertController = UIAlertController(title: "Logged In Successfully", message: "asda", preferredStyle: .Alert)
// Create the actions
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) { UIAlertAction in
self.dismissViewControllerAnimated(true, completion: nil)
}
// Add the actions
alertController.addAction(okAction)
// Present the controller
self.presentViewController(alertController, animated: true, completion: nil)
尝试在 dismissViewControllerAnimated 行中放置断点,并在按下“确定”时检查它是否到达那里。
如果不是 - 尝试替换
UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) { UIAlertAction in
self.dismissViewControllerAnimated(true, completion: nil)
}
有了这个:
UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) { _ in
self.dismissViewControllerAnimated(true, completion: nil)
}
我正在展示一个 UIAlertController
,而在 UIAlertAction
我正在关闭视图控制器。在 iOS 9.3 之前它工作正常。但在 iOS 9.3 中它不起作用。以下是代码。
let alertController = UIAlertController(title: "Logged In Successfully", message: "asda", preferredStyle: .Alert)
// Create the actions
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) { UIAlertAction in
self.dismissViewControllerAnimated(true, completion: nil)
}
// Add the actions
alertController.addAction(okAction)
// Present the controller
self.presentViewController(alertController, animated: true, completion: nil)
尝试在 dismissViewControllerAnimated 行中放置断点,并在按下“确定”时检查它是否到达那里。
如果不是 - 尝试替换
UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) { UIAlertAction in
self.dismissViewControllerAnimated(true, completion: nil)
}
有了这个:
UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) { _ in
self.dismissViewControllerAnimated(true, completion: nil)
}