我在这里看到很多类似的帖子,但是我在
Swift开发我的应用程序时都是关于Objective-C的.从图像中可以看到,我有一个登录屏幕视图,我正确地实现了登录机制.
现在我希望登录已经成功,然后显示标签栏控制器.在我的登录视图控制器我有这个功能登录:
var finalURL:NSString = "\(Settings.webServerLoginURL)?username=\(username)&password=\(password)" LoginService.requestLoginWithURL(NSURL(string: finalURL as String)!,completionHandler: { (success) -> Void in if (success) { NSLog("Login OK") /* Scarica dal database i tasks di LoggedUser.id */ /* Redirect al tab HOME dell'applicazione dove si mostrano il numero di task di quell'utente ed in cima "BENVENUTO: name surname" */ } else { self.alertView.title = "Autenticazione fallita!" self.alertView.message = "Username o passowrd." self.alertView.delegate = self self.alertView.addButtonWithTitle("OK") self.alertView.show() }
NSLog("Login OK")
但我不知道如何.我是Swift / XCode的初学者…如果你能解释我的话.
感谢所有读过的人.
解决方法
要从登录页面显示标签栏控制器,请将登录页面和TabbarController连接到显示段,并在属性检查器中指定标识符(说“mySegueIdentifier”).
要添加segue,只需右键单击并从登录视图控制器拖动到TabbarController.
成功登录后,您可以简单地调用“performSegueWithIdentifier”方法,如下所示
self.performSegueWithIdentifier("mySegueIdentifier",sender: nil)
在你的情况下,你在这一行之后调用它.
NSLog("Login OK")
如果您不想从登录页面导航到TabbarController,则还可以在成功登录后将其设置为rootViewController.
为此,请将标识符设置为TabbarController(说“myTabbarController”)
let appDelegate = UIApplication.sharedApplication().delegate! as! AppDelegate var initialViewController = self.storyboard!.instantiateViewControllerWithIdentifier("myTabbarControllerID") as! UIViewController appDelegate.window?.rootViewController = initialViewController appDelegate.window?.makeKeyAndVisible()
编辑:
Swift 3
let appDelegate = UIApplication.shared.delegate! as! AppDelegate let initialViewController = self.storyboard!.instantiateViewController(withIdentifier: "myTabbarControllerID") appDelegate.window?.rootViewController = initialViewController appDelegate.window?.makeKeyAndVisible()
快乐编码:)