Issue in hiding UINavigationBar in ios - iphone

I have a split view controller in my app's contact page.. and i am unable to hide the navigation bar in my page.. Can anyone help me on hiding the navigationBar. i have attached my code
- (void)viewDidLoad
{
self.navigationController.navigationBarHidden = YES;
splitViewController.navigationController.navigationBarHidden = YES;
appdelegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
[super viewDidLoad];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
{
[[VHeaderView sharedVHeaderView] viewWithCommonHeaderOnView1:self.view];
}
else
{
[[VHeaderView_iPad sharedVHeaderView_iPad] viewWithCommonHeaderOnView1:self.view];
}
[splitViewController.view setFrame:CGRectMake(0,48, 768, 1024)];
// [self.view removeFromSuperview];
//self.view.frame=CGRectMake(0,100, 768, 1024);
[self.view addSubview:splitViewController.view];
}

Try this. works for me. Make sure that navigation controller is allocated.
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES];
}
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO];
}

- (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];
}
put this code in your .m file
if u don't wish to animated effect then set no.

Callled only once this method.
try to put your code in ViewWillAppear
-(void)viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
try this code

Related

IOS 7 + For force controller Orientation to Portrait

I have used below code for IO6 and below to force rotate:
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
UIApplication* application = [UIApplication sharedApplication];
if (application.statusBarOrientation != UIInterfaceOrientationPortrait)
{
UIViewController *c = [[UIViewController alloc]init];
[c.view setBackgroundColor:[UIColor redColor]];
[self.navigationController presentViewController:c animated:NO completion:^{
[self.navigationController dismissViewControllerAnimated:NO completion:^{
}];
}];
}
}
But it is not working correctly on IOS7, it rotate view controller but again set blank view on screen...
Can you help me to solve this issue in IOS 7...
Change this line:
[self.navigationController dismissViewControllerAnimated:NO completion:^{
}];
To this:
[self.navigationController dismissViewControllerAnimated:YES completion:^{
}];

navigationController toolbar won't reappear after hiding

In my appDelegate, under applicationDidFinishLaunching, I have:
[self.navigationController setToolbarHidden:NO];
In a subview, under viewDidLoad I have:
[self.navigationController setToolbarHidden:YES animated:YES];
However, upon hitting back on the navigation controller, the toolbar remains hidden. I've tried adding this to the RootViewController with no success. I can't figure out what's going wrong.
[self.navigationController setToolbarHidden:NO animated:YES];
In your subview, you can do following:
- (void)viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES animated:animated];
[super viewWillAppear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewWillDisappear:animated];
}

presentModalViewController not responding

I have 3 classes.
First controllor is the first controllor in tabbar. I am using presentModalViewController to present a login screen and a Home screen. I have a presentModalViewController in firstcontrollor which present the login screen and in Loginscreen viewdidload method I have presentModalViewController which present home screen. The home screen presentModalViewController is dismissed in homePage_Btn_Clicked and presentModalViewController is dismissed in login_Btn_Clicked. The problem I have is my home screen is never presented. Any help? I am new in iPhone development.
//First Controllor
FirstControllor.m
- (void)viewDidLoad
{
[super viewDidLoad];
Accounts_Login *lvc = [[Accounts_Login alloc]initWithNibName:#"Accounts_Login" bundle:[NSBundle mainBundle]];
[self presentModalViewController:lvc animated:NO];
[lvc release];
}
//Login_view class
Login_view.m
- (void)viewDidLoad {
[super viewDidLoad];
Home_Screen *lvc1 = [[Home_Screen alloc]initWithNibName:#"Home_Screen" bundle:[NSBundle mainBundle]];
[self presentModalViewController:lvc1 animated:NO];
[lvc1 release];
user_ID_TextField.text = [[NSUserDefaults standardUserDefaults] objectForKey:#"User ID"];
}
-(IBAction) login_Btn_Clicked{
if ([services authenticate:credential_Data]) {
[self dismissModalViewControllerAnimated:YES];
[credential_Data autorelease];
}
//HomePage class
HomePage.m
-(IBAction) homePage_Btn_Clicked:(id) sender{
UIButton *theButton = (UIButton *)sender;
int count;
switch (theButton.tag) {
case 101:
count++;
[self dismissModalViewControllerAnimated:YES];
break;
default:
break;
}
}
Move presentModalView from viewDidLoad to viewDidAppear.
Try this:
Home_Screen *lvc1 = [[Home_Screen alloc]initWithNibName:#"Home_Screen" bundle:[NSBundle mainBundle]];
[self.parentViewController presentModalViewController:lvc1 animated:NO];
[lvc1 release];

iPhone: UINavigationController not showing new view

I have the following action that gets called when a button gets clicked. The log message gets printed yet, the view doesn't change. This function is in a UIViewController.
Any ideas what I am doing wrong? Why isn't the new view being displayed with a red background?
- (void)viewDidLoad
{
[levelButton2 addTarget:self action:#selector(clickButton) forControlEvents:UIControlEventTouchUpInside];
//MORE CODE
}
- (void) clickButton
{
NSLog(#"Clicked Button");
UIViewController *myViewController = [[UIViewController alloc] init];
myViewController.title = #"My First View";
myViewController.view.backgroundColor = [UIColor redColor];
//to push the UIView.
[self.navigationController pushViewController:myViewController animated:YES];
//[self.navigationController pushViewController:nextController animated:YES];
}
-(void) clickButton
{
NSLog(#"Clicked Button");
MyFirstController *myViewController = [[MyFirstController alloc] init];
[self.navigationController pushViewController:myViewController animated:YES];
[myViewController release];
}
Then after go into the MyFirstController.m file and
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
if(self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])
{
self.title = #"My First View";
}
return self;
}
I hope it will help you.
You havent used or mention NIB file in that controller..Add NIB file or else make set root view controller of a navigation with a view controller and push the view controller
You have to change your IBAction method a little bit as,
- (void) clickButton
{
NSLog(#"Clicked Button");
MyFirstController *myViewController = [[MyFirstController alloc] initWithNibName:#"MyFirstController" bundle:nil];
myViewController.title = #"My First View";
myViewController.view.backgroundColor = [UIColor redColor];
//to push the UIView.
[self.navigationController pushViewController:myViewController animated:YES];
//[self.navigationController pushViewController:nextController animated:YES];
}

add two navigation controller to one Tab bar Item

I want 2 navigation Controller to be attached to one Tab bar item.
Basically the idea is to have 2 views on a single tab Item and there should be a navigation bar to push and pop the screens. (same like settings application in iPad).
edited======
It will look like on left hand side there is a View with its own navigation Controller and on right hand side there is another View with its own navigation controller(or some other UI) to achieve the Push Pop stuff.
I know how to attach 1 navigation Controller to one Tab bar Item.
Edited For ModalView Issue:-
by implementing conmulligan code everything works property. But if I try to display some ModalViewController in lansdscape mode and when I try to close this ModalView the FirstViewController navigationbar becomes portrait(along with its View) and SecondViewController NavigationBar remains landscape(at it should be). This happens only in Device not in simulator.
Below is my Code of presenting the ModalViewController.
ModalTableViewController *modalTableViewController = [[ModalTableViewController alloc]initWithNibName:#"ModalTableViewController" bundle:[NSBundle mainBundle]];
UINavigationController *localNavigationViewController = [[UINavigationController alloc] initWithRootViewController:modalTableViewController];
localNavigationViewController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:localNavigationViewController animated:YES];
[modalTableViewController release];
[localNavigationViewController release];
For Dismising the ModalViewCntroller I do it as below:-
[self dismissModalViewControllerAnimated:YES];
Waiting for your replies.
One way would be to create a UIViewController subclass that contains two navigation controllers and add that to the UITabBarController. Here's how you'd create and layout the navigation controllers in the UIViewController's -viewDidLoad method:
FirstViewController *firstViewController = [[FirstViewController alloc] init];
UINavigationController *firstNavigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
[firstViewController release];
SecondViewController *secondViewController = [[SecondViewController alloc] init];
UINavigationController *secondNavigationController = [[UINavigationController alloc] initWithRootViewController:secondViewController];
[secondViewController release];
firstNavigationController.view.frame = CGRectMake(0.f, 0.f, 320.f, self.view.frame.size.height);
firstNavigationController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
secondNavigationController.view.frame = CGRectMake(321.f, 0.f, self.view.frame.size.width - 321.f, self.view.frame.size.height);
secondNavigationController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleRightMargin;
[self.view addSubview:firstNavigationController.view];
[self.view addSubview:secondNavigationController.view];
This is more or less how the UISplitViewController works under the hood.
Edit: you might need to add the following code to make sure it lays out properly:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[firstNavigationController viewWillAppear:animated];
[secondNavigationController viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[firstNavigationController viewWillDisappear:animated];
[secondNavigationController viewWillDisappear:animated];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[firstNavigationController viewDidAppear:animated];
[secondNavigationController viewDidAppear:animated];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[firstNavigationController viewDidDisappear:animated];
[secondNavigationController viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}