My app project has a basic of 5 page-views each linked through the tab bar across the bottom, and when I switch from page to page those 5 pages each have the tab bar on their page as they should, and work just fine.
Two of those 5 (tabbing) pages act like an index and I have button links that go to secondary pages. When I programed the buttons to go to the secondary pages the link worked fine but the tab bar at the bottom of those pages is no longer there. Each of the secondary pages have a return button to come back to the index page they linked out from, but the tab bar that was there when I linked out is now also gone.
As an experiment, to rule out the secondary pages as being the problem to the missing tab bar after the button click开发者_开发问答, I linked one of the tabs to go directly to a secondary page, and that experiment worked perfectly.
Here is the code I used to link up the out going button: In the class page tabIndex.h :
//I declared this method after the last "}"
-(IBAction)switchView:(id)sender;
In the class page tabIndex.m :
-(IBAction)switchView:(id)sender {
MyNewPageViewController *newPagelink = [[MyNewPageViewController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:newPageLink animated:YES];
[newPagelink release];}
Then I reversed the names and did the same in the respective .h & .m files for MyNewPageViewController for the back button, and called the IBAction for the return "switchBack"
I'm hoping someone can help me with a fix for this problem...
Many thanks,
--Rob
It sounds like you might be better off using navigation controllers in conjunction with the tab bar controller. Using the nav controller together with the tab bar controller will let you present multiple views organized hierarchically for each tab while keeping the tab bar visible the whole time.
When you want to go to the secondary page for a given controller, you'd use -pushViewController:animated:
to push the new controller onto the navigation stack; to return to the first controller, you'd simply -popViewControllerAnimated:
. You'll have a navigation view controller for each of the tabs that can have more than one view, with the view controller for the primary view as the nav controller's root view controller.
Complete details on using a nav controller with a tab bar controller are available in the View Controller Programming Guide.
It sounds like you have 5 view controllers with 2 of the 5 view controllers needing to use a navigation controller. For those vc, you would still like to see the tab bar, but need to be able to push and pop additional views onto them. That's easy enough. Here is how you would set up your tab car controller -- it assume that the first two view controllers are the ones you need to push additional views to:
MyVC1 *vc1= [[MyVC1 alloc] initWithNibName:@"MyVC1View" bundle:nil];
MyVC2 *vc2= [[MyVC1 alloc] initWithNibName:@"MyVC2View" bundle:nil];
MyVC3 *vc3= [[MyVC1 alloc] initWithNibName:@"MyVC3View" bundle:nil];
MyVC4 *vc4= [[MyVC1 alloc] initWithNibName:@"MyVC4View" bundle:nil];
MyVC5 *vc5= [[MyVC1 alloc] initWithNibName:@"MyVC5View" bundle:nil];
// these are the VCs you need to push/pop from
UINavigationController *firstNavController = [[UINavigationController alloc] initWithRootViewController:vc1];
UINavigationController *secondNavController = [[UINavigationController alloc] initWithRootViewController:vc2];
UITabBarController *tabBar = [[UITabBarController alloc] initWithNibName:nil bundle:nil];
tabBar.viewControllers = [NSArray arrayWithObjects:firstNavController, secondNavController, vc3, vc4, vc5, nil];
Now with vc1 and vc2 you can push views onto the navigation stack as your normally would, for example
[self.navigationController pushViewController:vc1B animated:YES];
精彩评论