crychair
crychair

Reputation: 347

iOS UINavigationController

I am having an issue when im using navigation controller. My program is laid out where I have a start screen (not in the navigation controller) and then when you press a button it sends you to the navigationController and new view.

Is there a way to get back out of the navigation controller back to that home screen using a back button.

OR if i included the start screen as the root for the navigation controller is there a way to hide the top bar in the view.

The reason i didn't include the start screen originally is because I didn't want the navigation bar on the screen.

Thanks.

Upvotes: 1

Views: 147

Answers (7)

Paras Joshi
Paras Joshi

Reputation: 20541

For hide the UINavigationBar then use bellow line in viewWillAppear: method of your start screen viewController..

[self.navigationController setNavigationBarHidden:YES]; 

OR

[self.navigationController setNavigationBarHidden:YES animated:YES];

AND you can go back to previous view and also home screen or parent view with bellow code...

-(IBAction)yourButton_Clicked:(id)sender{

    [self.navigationController popViewControllerAnimated:YES];//// For back to Previous view
  //  [self.navigationController popToRootViewControllerAnimated:YES]; // For Back to home screen or parent view

}

Upvotes: 2

cancerian
cancerian

Reputation: 942

U can hide the navigation bar using

self.navigationController.navigationBarHidden = YES;

Add the start screen as sub view to navigation's root view controller.

[self.view addSubview:startScreen.view]

Later Remove it by [startScreen.view removFromSuperview] and set the navigationBarHidden flag to NO.

Upvotes: 0

Harshal Chaudhari
Harshal Chaudhari

Reputation: 710

Actually your requirement are not clearer. But to hide your navigation controller you can use,

self.navigationController.navigationBarHidden=YES;

and also you can add your custom button on to the navigation bar.

UIBarButtonItem *leftBtn=[[UIBarButtonItem alloc]initWithTitle:@"Back" style:UIBarButtonSystemItemAction target:self action:@selector(backBtnClicked:)];
    self.navigationItem.leftBarButtonItem=leftBtn;

and you can right your requirements in the backBtnClicked: method. you can also navigate to your root level view controller.

Upvotes: 0

Macness
Macness

Reputation: 1226

If you're using storyboard you could create a UIButton and link the view back modally.

Also check out https://stackoverflow.com/a/8348527/401787 for navigating between view controllers.

Upvotes: 0

Lochana Ragupathy
Lochana Ragupathy

Reputation: 4320

   - (void) viewWillAppear:(BOOL)animated{

    [self.navigationController setNavigationBarHidden:YES animated:animated];

         [super viewWillAppear:animated];
 }

- (void) viewWillDisappear:(BOOL)animated{

    [self.navigationController setNavigationBarHidden:NO animated:animated];

[super viewWillDisappear:animated];
}

By implementing this on your home Screen you can hide the top bar

Upvotes: 0

iCreative
iCreative

Reputation: 1506

You can use navigation bar in all screens. But for the screen where you dont want to show it, Just use hide property for navigation bar. That screen will not show navigation bar on top.

[[self navigationController] setNavigationBarHidden:YES animated:YES];

It'll resolve your issue.

Upvotes: 0

IronManGill
IronManGill

Reputation: 7226

Well there is a very simple method to just hide the UINavigationBar when you want to like this in the ant view :-

[self.navigationController setNavigationBarHidden:YES];

and the in the view in which you would want to show it simply unhide it like this :-

[self.navigationController setNavigationBarHidden:NO];

Upvotes: 0

Related Questions