gpt4 book ai didi

ios - 从 View Controller 调用 TabBarController 委托(delegate) - Swift

转载 作者:搜寻专家 更新时间:2023-11-01 05:41:36 26 4
gpt4 key购买 nike

所以我有一个基于 Parse 后端构建的 iOS 应用程序。我在 AppDelegate 中设置了一个 UITabBarController 并且它工作正常。

class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
var tabBarController: UITabBarController?
var array: [AnyObject] = []

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Parse.setApplicationId("1040205491TFSDJT43T49T349F3I4T3J")
var navigationBarAppearance = UINavigationBar.appearance()
navigationBarAppearance.tintColor = uicolorFromHex(0xffffff)
navigationBarAppearance.barTintColor = uicolorFromHex(0x4183D7)
UIApplication.sharedApplication().statusBarStyle = UIStatusBarStyle.LightContent
let titleDict: NSDictionary = [NSForegroundColorAttributeName: UIColor.whiteColor()]
navigationBarAppearance.titleTextAttributes = titleDict
//navigationBarAppearance.clipsToBounds = true;
let tabBarController = UITabBarController()
let storyboard = UIStoryboard(name: "Storyboard", bundle: nil)
let myVC2 = storyboard.instantiateViewControllerWithIdentifier("navProfile") as UIViewController
let myVC1 = storyboard.instantiateViewControllerWithIdentifier("navigation") as UIViewController
let myVC3 = storyboard.instantiateViewControllerWithIdentifier("navComp") as UIViewController
var controllers = [myVC1,myVC3]
tabBarController.viewControllers = controllers
self.window?.rootViewController = tabBarController
var query = PFUser.query()
return true
}

但是我的应用程序使用登录,当用户登录时我希望显示选项卡栏 Controller 。这是我的登录 View Controller

@IBAction func SignIn(sender: AnyObject) {
LoginViewController().showActivityIndicator(self.view)
PFUser.logInWithUsernameInBackground(UsernameTextField.text,password: PasswordTextField.text){
(user:PFUser!, error:NSError!)->Void in
if user != nil{
println("Login successfull")
let storyboard = UIStoryboard(name: "Storyboard", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("navigation") as UIViewController
self.presentViewController(vc, animated: false, completion: nil);

然而,这链接到标识符为“navigation”的 UINavigationController有没有办法为在 Appdelegate 中创建的标签栏 Controller 发送 Storyboard标识符或以某种方式实例化到 View

最佳答案

开始从事类似的项目。我不知道这是否是最佳做法,但我会让 AppDelegate 检查是否有登录用户,然后选择应显示哪个 View 。

采用这种方法的主要原因是,如果您无法呈现其 View 不在窗口层次结构中的 View 。这样您就不会让 View 本身呈现然后呈现另一个 View ,从而使过程更加顺畅。

希望这有用

    var user = PFUser.currentUser()
if user == nil {
// Do stuff after successful login.
println("Login Not Succesful")
} else {
// The login failed. Check error to see why.
println("Login Succesful")
var rootViewController = self.window!.rootViewController
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
var viewController = mainStoryboard.instantiateViewControllerWithIdentifier("tabbc") as! UITabBarController

window?.rootViewController = viewController
window?.makeKeyAndVisible()

}

关于ios - 从 View Controller 调用 TabBarController 委托(delegate) - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29335414/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com