Accessing a view controller created through Storyboard using the App Delegate

后端 未结 7 1718
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-09 10:41

I\'m working on an iOS5 app using storyboard, and I have a method in a view controller class that i\'d like to access from the App Delegate. The trouble is, this view contr

7条回答
  •  眼角桃花
    2020-12-09 11:35

    Thanks to Jerry (above), here's the code that got me what I wanted:

        UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
    MasterViewController *result;
    
    //check to see if navbar "get" worked
    if (navigationController.viewControllers) 
    
        //look for the nav controller in tab bar views 
        for (UINavigationController *view in navigationController.viewControllers) {
    
            //when found, do the same thing to find the MasterViewController under the nav controller
            if ([view isKindOfClass:[UINavigationController class]])
                for (UIViewController *view2 in view.viewControllers) 
                    if ([view2 isKindOfClass:[MasterViewController class]])                    
                        result = (MasterViewController *) view2;
    }
    

提交回复
热议问题