【发布时间】:2016-05-11 01:21:59
【问题描述】:
所以我在 2 个视图控制器之间执行 segue 时遇到了问题。
让我们调用 2 个视图控制器
A:登录视图控制器
B:视图控制器
在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 的文本字段中输入我的 ID 并单击 Login 按钮时,它会触发如下错误:
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
并认为我的问题与 Mr. Paka 不同,因为我的注销按钮没有执行 segue,而是关闭了视图控制器本身,这反过来可能导致重叠。
有什么建议吗?
【问题讨论】:
-
你有没有找到解决这个问题的方法?我遇到了完全相同的问题。
-
@J.Doe:你找到解决方案了吗?
标签: ios xcode swift model-view-controller segue