问题
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