I have a navigation controller that loads a tableview, from here the user can select a row which loads a detail view that gets pushed onto the stack. This detail view controller has a segmented control in the bottom bar which loads in a series of views using [self.view insertSubview:firstDetailViewController.view atIndex:0]; etc...
That works fine - one of the subviews loaded also contains a table which loads another detail view. This caused problems because I couldn't access the navigation controller from within the sub view. To do so I had to use:
YourAppDelegate *del = (YourAppDelegate *)[UIApplication sharedApplication].delegate;
[del.navigationController pushViewController:nextViewController animated:YES];
Which I found here: Accessing a Top Navigation Controller from a Subview Navigation Controller.
But there's another instance where similar functionality is required. From the home view controller a lists view is loaded and presented modally. From here I push 2 detail views onto this new navigation stack using self.navigationController etc... which works fine. But when the subview tries to push the detail view it doesn't work. self.navigationController doesn't work, the appDelegate one pushes them onto the other nav controller and self.parentViewController.navigationController doesnt work.
Any ideas?
So your Home VC does presentModalVC of a table view. The table view does a self.NavCon pushVC: detail. And the detail then fails to push a sub-detail. Is that the scenario?
I'm wondering where the tableview got it's nav controller from, since it was presented modally, which does not require a NavCon.
I'm also wondering if you could push the tableview onto the NavCon instead of presenting modally; then the detail should have an intact NavCon which could then in turn push a sub-detail.
Hope that helps.
-Mike
Related
want my table to show up only half way from the bottom of the screen, the upper half meant for the calendar view. To do this, I added a table view through code using CGRectMake specifying the (x,y) co-ordinates I wanted it to start at.
Now, I want each row of this table to navigate to a new view. How do I make the navigation controller push my new view? I added a navigation controller to my main view
TaskDetailsViewController *detailViewController = [[TaskDetailsViewController alloc] initWithNibName:#"TaskDetailsViewController" bundle:nil];
[self.navigationController pushViewController:detailViewController animated:YES];
If you need to apply navigation from a view controller, that view controller should be a part of the navigation viewcontroller stack.
So what you have to do is instead of adding the rootViewController directly, You create a navigation controller, and set the rootViewcontroller to it(as rootViewController property). Once you set it, You can add navigation controller in place of rootViewController added previously.
Then on click you can use.
[self.navigationController push..... animated:..];
You can check it. If try to access the navigationController by self.navigationController currently it would be returning nil.
I'm attempting to create an application that has a regular view shown on start-up. It acts as a introduction view with two buttons that give the user choices to sign or register. After clicking sign in I present the form with presentModalViewController. After they finish with this I want to dismiss the modal view, and swap the introduction view with a tab bar controller that is the regular application.
I'm having a lot of trouble getting this to happen animated though. I did manage to get the modal view to transition out with the new view below it, but then immediately the introduction view is reshown, and I'm not sure why.
In the delegate I'm running this:
[window addSubview:firstRunController.view];
Presenting the view is very standard
This is how i'm dismissing it and getting the behavior I said above:
QuestionMeAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[self dismissModalViewControllerAnimated:YES];
[delegate.firstRunController.view removeFromSuperview];
If you maintain views by navigationController, you can assign view controllers by - (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated.
I did swap views by re-assigning view controllers of navigation controller first, and then call dismissModelViewController to leave current view controller or navigation view controller.
I have created View based application, here i need to navigate between views when button pressed.
so in first view controller i have created action for button pressed.
-(IBAction)loadSecondView:(id)sender
{
SecondView *sView = [[SecondView alloc]initWithNibName:#"SecondView" bundle:nil];
[self.navigationController pushViewController:sView animated:YES];
[sView release];
}
this code is not working, anything i am missing,
i can do this by [self.view addSubview:sView]; but i need navigation effect.
Thanks in advance.
You can't just hook a UIView instance to a navigation controller, that's not how they work.
Take a look at the "Navigation-based Application" template in Xcode, to learn how navigation controllers work.
You can use view controllers while hiding the navigation bar:
[[self navigationController] setNavigationBarHidden:YES animated:NO];
You can then map UIButton instances to selectors that push or pop view controllers, while keeping the navigation bar hidden.
These button instances are subviews of the view controller's view property.
Hiding the navigation bar can help provide the illusion that you are not using a navigation controller, while giving you all the functionality of the navigation controller.
Alex is right, if you create just a "View Based Application" project, no UINavigationController was created so when you push something on it nothing happen, that's normal.
You have to create a UINavigationController and make you main view its rootViewController, then you can push on it a new viewController.
I have got a solution for this,
In View based application the appdelegate file creates object for, view controller and added that view to main window, to do our task, delete the controller in mainwindow.xib and add a UINavigation controller,and create a object to it, and connect outlet to it,and then add this navigation controller view as a sub view,
its work fine.
I have a Navigation Controller with a root table view which has several links. Tapping each link moves to the next view (by pushing it to the navigation controller's stack). But suppose that in that "next view", I have a UIButton that should take me further to another view (by pushing on to the same navigation controller's stack)...
View Controller-->first view-->second view-->third view..........
Now, I can easily access the Navigation Controller when I deal with the first view (and successfully push it to the Navigation Controller's stack) because it has been instantiated in the same file itself. What my real doubt is--How do you access a Navigation Controller in a far off view controller (eg, the third view or fourth view etc)? Please note that I am not using any separate delegate. All the Navigation Bar methods have been implemented in one file and connected to the Navigation Controller via an outlet.
When you push a ViewController onto a NavigationController the ViewController will automatically have it's navigationController property set. This means you can access the same NAvigationController no matter where you are in the stack.
-Update-
navigationController
In every UIViewController you can access that property.
So to in any other UIViewController that has been pushed onto the stack you should be able to just do this:
[self.navigationController pushViewController:othercontroller animated:YES];
Look at the documentation for UIViewController to see what other magic properties you have available.
I have a view which contains a UIButton. When this is clicked, it calls a method that loads another NIB. Now, normally, that nib would load a view onto the stack, and everything would be fine. But, I am trying to load a Navigation Controller (so that I can have table views that are multiple levels deep), and all I get it errors.
What is the proper method for loading a Navigation Controller and putting it on the top of the stack?
As the other poster said you should create your Nav controller in your AppDelegate. If you are adding a new UIView to the stack like presentModalViewController you want to create the UIView then add the Nav Controller to it. If you don't want nav controller on that screen but the next just use the navController.hidden property I think it is.
To add the nav controller to the view do this:
NoticesView *noticesScreen = [[[NoticesView alloc] init] autorelease];
noticesScreen.delegate = self;
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:notices_screen] autorelease];
[self presentModalViewController:navController animated:YES];
Hope that helps towards your question. Still trying to find out exactly what your doing
Create the navigation controller in the app delegate. Push your mapview onto the stack as the first view. Push your tableview onto the stack as the second. If you started with a view-based app template, you won't have a navigationcontroller instantiated at all. (Been there done that) the easiest way out of this is to use xCode to make a navigation based applcation and then copy the code out of that. If you do already have a navigation controller, then just push the view controllers as above.