ios - Swift:如何在登录 View 后显示标签栏 Controller

标签 ios xcode swift uitabbarcontroller

我在这里看到过很多类似的帖子,但它们都是关于 Objective-C 的,而我正在用 Swift 开发我的应用程序。从图中可以看出,我有一个登录屏幕 View ,并且我正确地实现了登录机制。

enter image description here

现在我希望在登录成功后显示标签栏 Controller 。在我的登录 View Controller 中,我有这个登录功能:

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()
            }

所以我认为我应该在

之后显示标签栏 Controller
NSLog("Login OK")

但是我不知道怎么办。我是 Swift/XCode 的初学者……如果你能解释一下。 感谢所有阅读过的人。

最佳答案

要从登录页面显示标签栏 Controller ,请将登录页面和 TabbarController 连接到 Show segue 并在属性检查器中为其指定标识符(例如“mySegueIdentifier”)。

要添加 segue,只需右键单击并从 Login View Controller 拖动到 TabbarController。

在成功登录后,您可以简单地调用“performSegueWithIdentifier”方法,如下所示

self.performSegue(withIdentifier: "mySegueIdentifier", sender: nil)

在您的情况下,您可以在此行之后调用它。

NSLog("Login OK")

如果不想从登录页面导航到TabbarController,也可以在登录成功后设置为rootViewController。 为此,请将标识符设置为 TabbarController(说“myTabbarController”)

let appDelegate = UIApplication.shared.delegate! as! AppDelegate
let initialViewController = self.storyboard!.instantiateViewController(withIdentifier: "myTabbarControllerID")
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()

快乐的编码.. :)

关于ios - Swift:如何在登录 View 后显示标签栏 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32224416/

相关文章:

iphone - 如何从单 View 应用程序启动 cocos2D 游戏

iOS Webview UI 测试

ios - 添加按钮不在 tableView 上添加新行

ios - 滚动 UITableView 时随机崩溃

ios - 为 iOS(和 Airplay)上不受支持的硬件加速容器设计一个库

iphone - 获取 NULL 缓存

html - 如何在不滚动的情况下使页眉和页脚可见?

ios - Xcode 管理器控制台 : What is House Arrest

ios - Swift Array 正在从我的数组中打印单词 "optional"不想强制解包

swift - 解析 JSON - Alamofire