我是一个刚开始的敏捷开发人员,所以请在这里忍受。
我有一个多人游戏应用程序,并且从我的服务器上(是的,这是一个后台线程),我收到一个已找到匹配项的信号。然后执行此代码段
dispatch_async(dispatch_get_main_queue(), {
print("showing dialog")
let dialog = UIAlertController(title: "Game found", message: "You are playing with a person named "+self.player2.getName(), preferredStyle: UIAlertControllerStyle.Alert)
dialog.addAction(UIAlertAction(title: "cancel", style: UIAlertActionStyle.Cancel, handler: nil))
self.presentViewController(dialog, animated: true, completion: nil)
self.labelOpponentName.text = self.player2.getName()
})
但是,出现以下错误
Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<UIAlertController: 0x79151e00>)
另外,我的labelOpponentName没有更新其文本。这是为什么?
最佳答案
您的函数内部或全局可能定义了另一个UIAlertController。
dispatch_async(dispatch_get_main_queue(), {
print("showing dialog")
let dialog = UIAlertController(title: "Game found", message: "You are playing with a person named "+self.player2.getName(), preferredStyle: UIAlertControllerStyle.Alert)
dialog.addAction(UIAlertAction(title: "cancel", style: UIAlertActionStyle.Cancel, handler: nil))
self.presentViewController(dialog, animated: true, completion: nil)
self.labelOpponentName.text = self.player2.getName()
})
关于ios - 尝试在<Prisoners_Dillema.ControllerGame:0x788b1a00>上显示<UIAlertController:0x79151e00>,其 View 不在窗口层次结构中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33647183/