我单击了登录按钮,并在通知中心中引发了消息,并打开了一个国家选择器,当我在国家选择器中单击登录按钮时,视图视图必须打开,但会引发错误:
0x0的内存读取失败........
此错误发生在获取控制器对象和当前对象之间。 我现在该怎么办?
我正在使用Xcode 10.1和Swift 4
@objc func showSpinningWheel(_ notification: NSNotification) {
if whichbuttonclick == true
{
let vc = self.storyboard?.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController
self.present(vc, animated: true, completion: nil)
}
else
{
self.performSegue(withIdentifier: "Register", sender: self)
}
}
我希望它会跳过登录控制器,但会引发错误。
答案 0 :(得分:0)
This is how i add Notification Observer :
NotificationCenter.default.addObserver(self, selector: #selector(self.showSpinningWheel(:)), name: Notification.Name(rawValue: "opencontrollermessagenotification"), object: nil)
@objc func showSpinningWheel( notification: NSNotification)
{
if whichbuttonclick == true
{ self.performSegue(withIdentifier: "Login", sender: self) }
else
{ self.performSegue(withIdentifier: "Register", sender: self) }
}
and This is how i Post it :
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "opencontrollermessagenotification"), object: nil, userInfo: nil)