Tell UITabBar which view to load

▼魔方 西西 提交于 2019-12-08 13:32:48

问题


Is there 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.


回答1:


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];
     } 
}



回答2:


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.



来源:https://stackoverflow.com/questions/5676419/tell-uitabbar-which-view-to-load

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!