错误A的窗口不等于B的视图窗口

时间:2016-02-02 09:54:18

标签: ios xcode swift model-view-controller segue

所以我在两个视图控制器之间执行segue时遇到问题。

让我们调用2个视图控制器

A:LoginViewController

B:ViewController

Image

在B中我有一个"退出"按钮(它是一个左栏按钮项),当它点击时触发一个功能,如此,并调用dismissViewController并返回到A.

@IBAction func logOutButton(sender: AnyObject) {
    let actionController = UIAlertController(title: "Log out", message: "Are you sure you want to log out?", preferredStyle: UIAlertControllerStyle.Alert)

    let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default){UIAlertAction in
        self.prefs.setInteger(0, forKey: "ISLOGGEDIN")
        self.prefs.setInteger(0, forKey: "PERMISSIONTOLOADDATA")
        self.prefs.synchronize()

        print("User logged out")
        socket.disconnect()
        self.dismissViewControllerAnimated(true, completion: nil)
    }

    let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default){UIAlertAction in
        print("Test: Log out action cancelled")
    }

    actionController.addAction(okAction)
    actionController.addAction(cancelAction)
    self.presentViewController(actionController, animated: true, completion: nil)
}

此处没有任何问题,但是当我在A&#39的文本字段中输入我的ID并点击登录按钮时,会触发如下错误:

2016-02-02 17:33:12.879 iCare[3852:190330] <UIView: 0x7facd153cfd0; frame = (0 0; 375 667); alpha = 0.95; autoresize = W+H; tintColor = UIDeviceRGBColorSpace 1 1 1 1; layer = <CALayer: 0x7facd153d140>>'s window is not equal to <UINavigationController: 0x7facd187ae00>'s view's window!

登录按钮的代码:

@IBAction func LoginButton(sender: AnyObject) {

    let logInUserID = loginPatientID.text
    let logInUserIDUpper = logInUserID?.uppercaseString
    if (logInUserIDUpper!.isEmpty){
        displayAlertMessage("Please enter your Patient ID!")
        return
    }else{
        print("Test: requesting login permission from database")
        loginSocket.emit("loginRequest", logInUserIDUpper!)
        print("Test: requested")

        loginSocket.on("loginReply") {data, ack in
            let jsonLogin = JSON(data)
            if jsonLogin[0].intValue == 1{
                print("Test: ID Matched, putting up ViewController")

                self.prefs.setObject(logInUserIDUpper, forKey: "AppUserID")
                self.prefs.setInteger(1, forKey: "ISLOGGEDIN")
                self.prefs.synchronize()
                loginSocket.disconnect()

                self.loginPatientID.resignFirstResponder()
                self.performSegueWithIdentifier("gotoVC", sender: self)
            }else if jsonLogin[0].intValue == 0{
                self.displayAlertMessage("Sorry, you are not assigned to this program")
            }else if jsonLogin[0].intValue == 3{
                self.displayAlertMessage("Internet is not stable, please try again later")
                print("Test: Query problem")
            }else{
                print("Test: not getting anything from ID database")
            }
        }//socket.on
    }//else
}//login button

我提到This

并且认为我的问题与Paka先生不同,因为我的退出按钮没有执行segue而是解雇了视图控制器本身,这反过来可能导致重叠。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

从VC的视图创建到目标VC(而不是从按钮到目标VC)的序列。这将解决“窗口不相等”的问题