开发者

Accessing a tabBarController from a class that didn't create it?

I'm developing an iPhone app, in which the first thing the end user sees is a "home" screen with five UIButtons. Upon tapping any one of those buttons, They're taken to a tab bar controller view with five tabs on the bottom, corresponding to the each of the UIButtons on the (now) previous home screen.

I'm currently creating my tab bar controller in my App Delegate, and loading the home view controller in the same place.

But I can't get the UIButtons in the Home View Controller to work. I call the different tabs like such:

- 开发者_JS百科(void) homeBtnSelect:(UIButton *)button {
    if (button == button1) {
    self.tabBarController.selectedIndex = 0;
    }
    if (button == button2) {
        self.tabBarController.selectedIndex = 1;
    }
    //etc etc...
}

I'm assuming I'll need to load the tabBarController into the home view controller. But I don't know how to do that. Can anyone help?

I can provide more code if needed. Thanks in advance!


In order to select particular viewController you have to set selectedViewController property..... you can do this by getting viewcontroller from tabBarController.viewControllers array..... and then setting selectedViewController property.......

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜