开发者

UITabbarController setting view

I have a UITabbarController set by the Interfacebuilder. The tabbarcontroller has 5 tabs, the first is a welcome page, and the second is a UITableViewController. Both have a NavigationController. The 2nd tab should show a category list. When I launch the app, all is fine. When I press the 2nd tab, it load the view perfectly with the navigation controller. But what I want to do is to be able to load a certain category in the 2nd tab using a link in the first tab.

So what I did was I added the following function in my appDelegate and call is from the view in my first tab:

- (void)loadCategoryViewUsingCategoryId:(NSString*)categoryId
{
    CategoryViewController *categoryView = [[CategoryViewController alloc] initWithLoadingCategoryUsingCategoryId:categoryId];

    if (!categoryView) {
        UIAlertView *errorView;
        errorView = [[UIAlertView alloc]
                     initWithTitle: NSLocalizedString(@"Whoops", @"oddsAppAppDelegate")
                     message: NSLocalizedString(@"I did not found the requested category. Sorry!", @"oddsAppAppDelegate")
                     delegate: self
                     cancelButtonTitle: NSLocalizedString(@"Close", @"oddsAppAppDelegate") otherButtonTitles: nil];
        [errorView show];
        [errorView autorelease];
    }
    else {
        self.tabBarController.selectedIndex = 1;

        self.tabBarController.selectedViewController = categoryView;
        [self.tabBarController.selectedViewController setTitle:@"apa"];
        [self.tabBarController.selectedViewController viewDidLoad];
    }
}开发者_如何学C

This works perfectly, BUT... when the 2nd tab is loaded it doesn't have the navigation controller toolbar. How can I load it so I keep my navigation controller toolbar?

The "CategoryViewController" is a UITableViewController by the way.

Best regards,

Paul Peelen


The Navigation Bar shall be visible by default. If you want to access it directly with

[[self navigationController] setNavigationBarHidden:NO];

I think your problem is somewhere else. If you assign your controllers like this

UITabBarController *theTabBar = [[UITabBarController alloc]init];
YourWelcomeViewClassHere *welcome = [[YourWelcomeViewClassHere alloc] initWithNibName:@"YourWelcomeViewClassHere" bundle:nil]; //Or other custom initalizers
UINavigationController *welcomeNav = [[UINavigationController alloc] initWithRootViewController:welcome];
CategoryViewController *category = [[CategoryViewController alloc] initWithNibName:@"CategoryViewController" bundle:nil]; //Or other custom initalizers
UINavigationController *categoryNav = [[UINavigationController alloc] initWithRootViewController:category];
/*
Your other View controllers initializations
*/

NSArray *viewControllers = [[NSArray alloc] initWithObjects:welcomeNav,categoryNav,/* other viewControllers ,*/nil];
[theTabBar setViewControllers:viewControllers];

This might work and show your views.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜