开发者

Tell UITabBar which view to load

Is there开发者_Python百科 a way to load views according to some states when touchingon UITabBar button? For example I touch "Home" button View1 loads. Than i do some code and when i touch "Home" button again View2 loads.


It can be done ...Suppose we have two view in memory myView1 & myView2..

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
     if(OnPressHomeTabBarButton) // Put your condition at this place  
     {
        [myView1 removeFromSuperview];
        [self.view addSubview:myView2];

     }
     else 
     { 
        [myView2 removeFromSuperview];
        [self.view addSubview:myView1];
     } 
}


Yes you can set the property viewControllers.

Look at this note from the documentation:

If you change the value of this property at runtime, the tab bar controller removes all of the old view controllers before installing the new ones. The tab bar items for the new view controllers are displayed immediately and are not animated into position. When changing the view controllers, the tab bar controller remembers the view controller object that was previously selected and attempts to reselect it. If the selected view controller is no longer present, it attempts to select the view controller at the same index in the array as the previous selection. If that index is invalid, it selects the view controller at index 0.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜