0

Ok, so how would i go about performing this operation.

  1. I have a tab bar
  2. In one view controller of the tab bar there are two buttons
  3. 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.
  4. 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 :)

CodeGeek123
  • 4,341
  • 8
  • 50
  • 79

1 Answers1

3

presentModalViewController is 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.

tabbar
|
+- navigationController1
|     |
|     +- myViewController1
|
+- navigationController2
      |
      +- myViewController2

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 myViewController1 is correctly inserted as the root view controller of navigationController1, then you can easily present subsequent viewcontrollers like this:

//in myViewController1
[self.navigationController pushViewController:myViewController3 animated:YES];
Community
  • 1
  • 1
hlynbech
  • 662
  • 4
  • 13
  • This works initially. But in navigationController1 i want two viewcontrollers (this is because viewcontroller1 appears when i press button a, and viewcontroller2 appears when i press button B, and both buttons are on the navigationControllers rootviewcontroller)? Any solution? – CodeGeek123 Oct 16 '12 at 16:27