I'm writing my first iPhone app and I am trying to figure out how to have a MasterView and DetailsView like in the example. However, instead of using a TableView, I want to use a button on the MasterView to go to the SignUpView. I want the MasterView to NOT have a navigation bar but the SignUpView needs to have one.
I have tried putting a NavigationController into the MasterView using the interface builder. This doesn't seem to do anything at all ... I.e. I make the following call:
[self.navigationController pushViewController:signUpViewController animated:YES];
And nothing happens. The SignUpView is never shown.
So then I declared a NavigationController in the AppDelegate. The above call in the same function that it was in before (button handler, button is in MasterView) works now! It takes me to the SignUpViewController.
however, the issue is, when I press back on the navigation bar in the sign up view, the navigation bar shows up again in the MasterView. I tried to set
self.navigationController.navigationBarHidden = YES;
in viewDidLoad and viewDidAppear, but that causes a black bar to appear in the transition from SignUpView to MasterView.
I tried to not set it in one of the two, and that causes the animation to go smoothly, but the navigation bar shows up in the MasterView.
I feel like this should be pretty simple to do ... but I'm at my wits end trying to figure this out. Some help would be really appreciated!
Thanks.
Probably not the answer to your question, but just a small suggestion. In the many apps that I have come across, a sign-up/sign-in view is generally displayed as a modal view (on top of your master view) with a 'cross' in the top-right corner to dismiss it. Probably it results in a better user experience.
Also, did you try self.navigationController.navigationBarHidden = YES; in the MasterView's viewWillAppear ?
HTH,
Akshay
I had this problem too, until I discovered setNavigationBarHidden. You will probably want to use these in viewWillAppear/viewWillDisappear or viewDidAppear/viewDidDisappear. You don't want to call this in viewDidLoad because that is only called once when the view is initialized, not every time it appears.
To hide:
[self.navigationController setNavigationBarHidden:YES animated:YES];
To show:
[self.navigationController setNavigationBarHidden:NO animated:YES];
Related
This is a follow up on a previous unsolved post.
I have a navcontroller, a tableview controller and a searchbar in the tableview. All this is built in storyboard.
I then build another viewcontroller programmatically when a cell is selected.
I do not want the navigation bar to appear in this last view so, in viewWillDisappear I call
[self.navigationController setNavigationBarHidden:YES animated:animated];
This works just fine IF I select a cell in the main tableView.
However, if the cell is selected after narrowing the data from a search in searchbar, then, the navigationbar will appear in the subsequent view although the call to setNavigationBarHidden is made in viewWillDisappear.
I tried repeating this call in viewDidDisappear and, now, the navigation bar disappears from the subsequent view although it is briefly displayed.
I would like to know what happens between the calls to viewWilldisappear and viewDiddisappear that apparently resets the NavigationBarHidden property?
This is what I found: The NavigationBarHidden property is apparently reset because when the searchbar leaves the view, it will send the navigationbar again on the view.
I am not sure I understand exactly what is happening, but this line of code in my viewWillDisappear solves the problem:
self.searchDisplayController.active=NO;
followed by:
[self.navigationController setNavigationBarHidden:YES animated:animated];
Of course, I would love to hear from someone who really understands what happens here.
I recently started using interface builder, the problem i'm facing right now is when i use the back button of navigation controller, my UI elements' y axis go up by roughly 20-30 px, is there some setting i've to use to avoid this problem ? And they go up only when i use pushViewController, when i use popViewController it loads the way i need.
Code i'm using for pushing:
examVC=[[ExampleClass alloc] initWithNibName:#"ExampleClass" bundle:nil];
[[self navigationController] pushViewController:examVC animated:YES];
I'm attaching the images with the question. Please note how label has gone down about 20-30 px.
Why does this happen? What am i doing wrong ?
Thanks for all the help.
Edit : changed the screens for better clarity
I'm using pushing code on the round rect button.
Screen 1:UI elements set in my IB
Screen 2: How it looks when pushed from previous view
Screen 3: How it looks when popped from the "Next View"
My home view controller had the navigation bar hidden, the screen i posted was the second view which comes after the home view. I wanted to hide navigation bar in the first view only, so i had used :
- (void)viewDidDisappear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewDidDisappear:animated];
}
It caused the problem because i was showing the navigation bar again in viewDidDisappear, so the view would load first then the navigation bar would be shown causing it to overlap.
So i put the same code in viewWillDisappear, which removed the issue. As navigation bar did load before loading of the next view. Now the view loads just like i designed it in interface builder.
Hey I don't know whether it will work for you or not but in your IB change top bar None to Navigation Bar
Then adjust your element accordingly and tun the code.
I tried all of the suggestions here and none of them worked. My UI elements were always lower when popping back to my original view controller. The only thing that fixed this for me was going into my nib file in Interface Builder and turning off Auto Layout.
I have a Navigation controller in a storyboard, currently with two screens. Screen1 contains an opening logo and some buttons, and I have hidden the navigation bar at the top using:
[[self navigationController] setNavigationBarHidden:YES];
in viewDidLoad and viewWillAppear: (in viewWillAppear I have it set with animated:YES, so it slides off when coming back from other screens).
When I go to Screen2, I have:
[[self navigationController] setNavigationBarHidden:NO animated:YES];
in the first view controller's viewWillDisappear, and the navigation bar slides in all nicely when that view comes on to the top of the navigation stack.
Problem is, when I tap back, the navigation bar animates off the right side of the screen, but Screen2 stays there, revealing another navigation bar underneath!
I can then tap back again and it will push Screen2 off and the main screen shall return, but this is not behaviour I want to pass on to any users, obviously!
Anyone had this issue before, or have any points on what might be the culprit?
Edit: I just found an error appearing when I run the iOS Simulator:
2011-11-02 19:29:13.548 TestHTML5[10261:f803] Unbalanced calls to begin/end appearance transitions for <LessonViewController: 0x6c5e960>.
This happens when I click the button to go the the second view (LessonViewController).
Hopefully that might be the thing to crack this, anyone know?
I found my IBActions, which contained:
SecondViewController *X = [self.storyboard instantiateViewControllerWithIdentifier:#"X"];
[self.navigationController pushViewController:X animated:NO];
on each were causing the view to double up or something like that. When I commented these two lines out in each IBAction, the problem disappeared.
Thanks heaps to #CodaFi for helping me through possibilities for this, to be honest, this solution doesn't make sense to me, even thought I can see it working here.
I'm writing an iPhone app that is based on a UINavigationController. I'm pulling data from a server that sometime returns bogus links. I open each link by pushing a webview viewcontroller. I want to be able to include some error handling. I know if the link is no good. So I want to be able to pop the webview view controller as soon as I know that my webview has encountered an error.
Currently, I've tried using the following code:
[self.navigationController popViewControllerAnimated:YES];
I then get a Navigation bar with nothing displayed in it, but if I click where the "back" button should be it operates appropriately. The title pops up when I click where the "back" button should be. The view where the viewcontrollers usually display there content is blank white too even though I'm popping back to a UITableViewController.
I've tried this as a workaround:
UINavigationController *nav = self.navigationController;
[self.navigationController popViewControllerAnimated:YES];
[nav.visibleViewController.view setNeedsDisplay];
I've checked the viewControllers array in the UINavigationController and it has the right viewcontrollers in it (ie it has removed the viewcontroller for the webview).
I also tried putting code in the viewWillAppear of the viewcontroller I'm popping back to, but the method is never getting called.
I'm looking for a way to force the UINavigationController to reload the same way that you can call reloadData on a UITableView.
Any help would be greatly appreciated.
I saw something like this on my app where I was using a navigation bar I added in Interface Builder on the root view of a navigation controller and then programmatically creating the nav bar and its subviews for the second view. When I would pop the second view to return to the first view I would hide the self.navigationcontroller bar which would show the white space underneath until the IB nav bar of the previous view appeared. To fix this I decided to stick with programmatically creating all my navbars which fixed the issue for me.
TL;DR - if you are using both IB and programmatically made navbars this can happen when popping views, stick with one or the other for all the navbars yo
This is the situation:
I have a tab bar with 2 tabs. Tab01 and Tab02.
In Tab01 I have a button which pushes repVC:
repVC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:repVC animated:YES];
[(UIViewController *)[tabController.viewControllers objectAtIndex:0] setView:repVC.view];
[repVC release];
Inside repVC I have another button which pushes an MFMailComposerViewController:
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
[self presentModalViewController:mail animated:YES];
[mail release];
The problem is: when mailView is shown(in Tab01) and I click Tab02, then back to Tab01, the mailView is hidden and even if I click the email button again, the view won't be presented.
So what I have is: Tab01.view -> repVC.view -> mail.view
For repVC, I use this line when I push the view so that even if I go switch tabs, that view will still be activated:
[(UIViewController *)[tabController.viewControllers objectAtIndex:0] setView:repVC.view];
But I can't do the same for mail because tabController is declared in another class which I cannot import. So I can't access the tabController and set the view for Tab01.
Hope the edit helped the understanding.
Hmm,
I still would suggest to use a Navigationcontroller. Would make things way easier, is conform to apple guidelines and suggestions and is pretty fast implemented. (Just create a Navigationcontroller, put the View of Tab1 as main view and hand it over to the TabbarController. Then for the mailView use [self.navigationController pushViewController:mail animated:YES]; Then the navcontroller "saves" the present view for you when u switch tabs)
But if for some Reason you have to use a modalViewcontroller you could either just deactivate the tabbar while the ModalView is shown or try to implement a switch or a simple if...else case in your ViewWillAppear where u check what screen to load.
Then Clean out the Window and load the right screen.
Hope you get the idea of what I mean, sometimes my way of writing seems to confuse people. ^^
A little more information would be great.
How did u set up your TabbarController?
How do u push the new view? Within a UINavigationController? If not, then do it with a navController, he should save the actual state of view and your problem should be solved.
If u already use a navController please post your ViewDidLoad and ViewWillAppear of the Viewcontroller of Tab 1
As #Amandir points out you could probably solve your problems by using a UINavigationController. I get a feeling that you are trying to abuse the modal view controller concept a bit and that's why it doesn't work as you expect. When you use presentModalViewController:animated: the intention should be that you are displaying a view that is modal, i.e. the user must interact and dismiss the modal view before she can continue.
What the paragraph above means that when you present a modal view controller it shouldn't be possible to use the tab bar. Since you are using the word push I'm guessing that you would like change the view of Tab01 while still being able to use the functionality of the tab bar. The problem is that there isn't any built-in method of pushing view controllers besides UINavigationController. persentModalViewController:animated: should only be used in case where you want a modal view, which on the iPhone means a full screen view.
The easiest way would probably be to use an UINavigationController and hide the navigation bar. Then you would get the functionality I think you are after. The other option is to manually add and remove sub views.
[self.view addSubview:repVC.view];
and
[repVC.view removeFromSuperview];
[self.view addSubview:mail.view];
You can use block animations if you want some fancy transitions.