Ok, so how would i go about performing this operation.
- I have a tab bar
- In one view controller of the tab bar there are two buttons
- when i click on the button1 it should take me to a different screen but it has to have the tab bar at the bottom.
- when i click on the button2 it should take me to a different screen but again has to have the tab bar at the bottom.
I tried
1. presentModalViewController – but that just covers the whole screen
2. added the second screen as subview to the first screen. – This showed the second view that i wanted to see and also had the tab bar at the bottom. however it was not functional. meaning i had a scrollview etc embedded in the view that comes but none of that work when adding as subview
3. Navigation Controller – i thought this should be the way and again tried adding a new nav controller within viewdidload but the program crashes.
@interface SettingsViewController : UIViewController <CLLocationManagerDelegate>
@property (nonatomic,retain) UINavigationController * navigationController;
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view setBackgroundColor:[[ApplicationResources applicationResources]lightGreyColour]];
self.postCodeTextField.hidden = TRUE;
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self];
[self.view addSubview:self.navigationController.view];
//self.facebookSwitch
}
So what is the solution? Thanks 🙂
presentModalViewControlleris exactly meant to cover the whole screen.It seems you want a navigation controller in each tab, so each tab has it’s own navigation stack. The trick is that you should add the navigation controller to the tab bar, and then your view controller to the navigation controller.
From the code above, it seems you’ve missed the point that UIViewController already has a property named
navigationController, so you shouldn’t declare it yourself.For setting up a navigation controller properly, see Tab Bar Application With Navigation Controller
When
myViewController1is correctly inserted as the root view controller ofnavigationController1, then you can easily present subsequent viewcontrollers like this: