【发布时间】:2015-10-03 09:20:04
【问题描述】:
我正在开发一个应该隐藏在登录视图后面的应用程序。
所以一般来说,我有一个标签导航控制器,它应该容纳几乎整个应用程序,我的逻辑是当应用程序加载时,初始视图控制器是标签导航控制器,如果用户登录,它会显示其第一个视图在。如果它没有登录,他们应该看到登录/注册页面。登录和注册页面都可以使用 Parse,它们都可以并且运行良好。它们以模态方式(使用 segues)呈现在选项卡视图控制器中的第一个视图之上。
问题是当我登录时(并且我确认它可以工作!)登录视图控制器没有被关闭以查看选项卡视图控制器,我认为我可能在 segues 中搞砸了。如果用户未登录,则显示登录视图的 segue 是从受保护的视图(不是导航控制器,虽然我也测试过,但不起作用)到登录视图控制器。
另外,受保护页面中的代码是这样的:
override func viewDidAppear(animated: Bool) {
self.performSegueWithIdentifier("segueToLoginView", sender: self)
}
这是我的故事板的样子:
所以,登录 segue 以模态方式呈现,这是我的登录按钮代码。
@IBAction func loginButtonTapped(sender: AnyObject) {
let username = usernameTextField.text
let password = passwordTextField.text
// Sends to Parse to see if user exists
PFUser.logInWithUsernameInBackground(username!, password: password!) {
(user: PFUser?, error: NSError?) -> Void in
if user != nil {
// LOGIN Successful
NSUserDefaults.standardUserDefaults().setBool(true, forKey: "isUserLoggedIn")
NSUserDefaults.standardUserDefaults().synchronize()
self.dismissViewControllerAnimated(true, completion: nil)
print("User logged in")
} else {
// Display Failed Login Alert message with confirmation
let failedLoginAttepmt = UIAlertController(
title: "Ups!",
message: "Something went wrong, try again...",
preferredStyle: UIAlertControllerStyle.Alert
)
let confirmAction = UIAlertAction(
title: "OK!",
style: UIAlertActionStyle.Default)
{ action in
self.dismissViewControllerAnimated(true, completion: nil)
}
failedLoginAttepmt.addAction(confirmAction)
self.presentViewController(failedLoginAttepmt, animated: true, completion: nil)
print("Could not find the user")
}
这行代码self.dismissViewControllerAnimated(true, completion: nil) 应该关闭模态显示的登录视图控制器,因为我确实在控制台中看到了打印语句。
我的错在哪里?
【问题讨论】:
标签: ios xcode swift parse-platform segue