Displaying a new view and Tab Bar Controller in iOS
I am trying to achieve the following but dont know the best way to go about it so any tips would be great.
My app has a first root view which has a tab bar with 4 tabs, one of the tabs contains a table view. When an item is selected on the table view I want to display a details page (which I can do fine) but also completely change the tab bar to match the new set of data.
A good example of this is the free F1 开发者_开发百科2011 app. When selecting "Live Timing" you are taken to a new screen with a different tab bar (with a home button at the top to get back to previous screen.)
How would be the best way to go about implementing this?
Thanks in advance.
Fraser
Just create a new tabbarcontroller view (as you would do in the app delegate) in the didSelectRowAtIndexpath: method.
Try linking the the view controller with the table to the new UITabBarController and make it a modal segue. In the class for your viewcontroller with the table do an
#import "FirstViewControllerInNewTabBar"
Then in the
(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
method you will want to do the following:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
// Since your segue is pointing to the new tab bar controller
UITabBarController *tabBarController = (UITabBarController *)segue.destinationViewController;
// Now you want to pass data into the new tab bar's view controllers
FirstViewControllerInNewTabBar *vc = (FirstViewControllerInNewTabBar *)[tabBar.viewControllers objectAtIndex:0];
// Assuming FirstViewControllerInNewTabBar has a property 'NSString *dataToPassIn'
vc.dataToPassIn = @"Potato";
}
精彩评论