您的位置:首页 > 移动开发 > Swift

swift下如何配置引导页后跳转rootViewController

2015-10-29 21:24 567 查看
在写一个小demo的时候发现如果将rootViewController定义在引导页(欢迎页)上时,之前设置的导航栏和tabBar都不能正常显示于是查书查到

class AppDelegate:
UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(application:
UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject:
AnyObject]?) -> Bool {

        //先设置欢迎页

let vc =
ViewController()

        //将欢迎页设置为根视图

self.window?.rootViewController = vc

        self.window?.backgroundColor =
UIColor.whiteColor()

        //调用闭包

vc.startClosure = {

        () -> Void
in

            self.start()

        } 

    }

    //闭包所用的方法,用来启动之后的View,并且修改根视图

    func start(){

        let vc1 =
SecondViewController()

        let vc2 =
ThirdViewController()

        let vc3 =
FoutViewController()

        let vc4 =
FifthViewController()

        vc1.tabBarItem.title =
"1"

        vc2.tabBarItem.title =
"2"

        vc3.tabBarItem.title =
"3"

        vc4.tabBarItem.title =
"4"

        let tabber =
UITabBarController()

        //设置UITabBarController

tabber.viewControllers = [vc1,vc2,vc3,vc4]

//设置UINavigationController的根视图,这里的根视图必须为tabber而不是欢迎页(vc)

        let navi =
UINavigationController(rootViewController: tabber)

        self.window?.rootViewController = navi

    }
再回到欢迎页里设置闭包

var startClosure : (() ->
Void)?
并在欢迎页跳转后面View的func里面调用这个闭包即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息