I have one issue with UInavigationcontroller
In my firstview i have button.If i click that button it should open tableview in secondview .If i click tableviewcell is connect to third view.it is second and thirdview used to the navigationbar
Please help in this issue.
in appDelegate create a navigationcontroller like this i am posting sample code
HomeScreen *homeScreenObject=[[HomeScreen alloc] initWithNibName:#"HomeScreen" bundle:nil];
self.navController =[[UINavigationController alloc] initWithRootViewController:homeScreenObject];
[homeScreenObject release];
[window addSubview:[navController view]];
// Override point for customization after application launch
[window makeKeyAndVisible];
navController is instance Variable declared in header file
UINavigationController *navController;
now on your firstviewcontroller create a IBAction and bound your button's touch down event with that action and use these lines in that method
ViewController *ViewControllerObject = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
[self.navigationController pushViewController:ViewControllerObject animated:YES];
[ViewControllerObject release];
so the viewController should have a tableView and on tableView's delegate method "didSelectRowAtIndexPath" use the above code for further navigation
Related
I have a UIViewController, I want to navigate from this view to my second view controller
SecondView *secondView=[[SecondView alloc] initWithNibName:#"SecondView" bundle:nil];
[self.navigationController pushViewController:secondView animated:YES];
[secondView release];
It doesn't work. It doesn't do anything and there is no error. What I'm missing?
SOLUTION
In Appdelegate file I've added a navigationcontroller.
UINavigationController *navCtrlr = [[UINavigationController alloc]initWithRootViewController:self.viewController];
[self.window setRootViewController:navCtrlr];
navCtrlr.delegate = self;
navCtrlr.navigationBarHidden = YES;
Is your view controller already inside a navigation controller otherwise it wont work. put an NSLog on self.navigationcontroller and see what it is printing
I have an alternative flow in my app. This flow starts in my firstViewController, then in this view a call my secondViewController like this:
- (IBAction)PressButton:(id)sender {
SecondViewController *second = [[SecondViewController alloc] init];
second.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
UINavigationController *nav = self.navigationController;
[nav presentViewController:second animated:YES completion:nil];
}
In my secondViewController I want to push my thirdViewController. But it is not working I tried this ways:
- (IBAction)pressButton:(id)sender {
ThirdViewController *tvc = [[ThirdViewController alloc] init];
UINavigationController *nav = self.navigationController;
[nav pushViewController:tvc animated:YES];
}
When I press the button of secondViewController nothing happens.
What I'm doing wrong ?
I'm using:
OSX 10.8.2
Xcode 4.6
iOS 6.1
You must present the navigation controller modally, and have the second view as the root of that navigation controller. As well as calling presentViewController from the owning view not its parent navigation controller.
- (IBAction)PressButton:(id)sender {
SecondViewController *second = [[SecondViewController alloc] init];
second.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:second];
[self presentViewController:navigationController animated:YES completion:nil];
}
Instead of presenting just the second view controller, make sure to present an additional navigation controller.
SecondViewController *secondViewController = [[SecondViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:secondViewController];
[[self navigationController] presentViewController:navigationController animated:YES completion:nil];
If you are using storyboard just click on the source view xib, Ctrl+drag to destination (Create Segue), select modal from popup menu.Click on the newly created connection. Add a name for it then in source view controller [self performSegueWithIdentifier:#"Segue Name" sender:self];
If you are trying to get a button to direct you to a different page modally, you can go into the storyboard or xib file. Control click from that button to the view controller you want to go to. and then the popup menu will give you the options of what type of outlet you want to use. Hope this helps
I'm having trouble initializing a viewcontroller when the app loads in my app delegate. The viewcontroller loads okay, but it overlaps the tabbar that I have at the bottom. Do I need to create another viewcontroller and have it load into that in the app delegate? I currently have a tabBarController set up in my MainWindow.xib, which contains Navigation controllers and inside those are viewControllers.
Here is my code...
In my didFinishLaunchingWithOptions I have:
sub = [[SubGabViewController alloc] initWithNibName:#"SubGabViewController" bundle:nil];
nav = [[UINavigationController alloc] initWithRootViewController:sub];
[window addSubview:nav.view];
Should it be something like?
sub = [[SubGabViewController alloc] initWithNibName:#"SubGabViewController" bundle:nil];
nav = [[UINavigationController alloc] initWithRootViewController:sub];
[newViewController.view addSubview:nav.view];
Thanks!
If you're trying to use a UITabBarController, each tab has its own root view controller (these can even be UINavigationController objects). Assuming you have a property for self.tabBarController (I think this gets created by default in Xcode if you are doing a tab-bar app), then:
sub = [[SubGabViewController alloc] initWithNibName:#"SubGabViewContrller" bundle:nil];
nav = [[UINavigationContoller alloc] initWithRootViewController:sub];
[self.tabBarController setViewControllers:[NSArray arrayWithObject:nav] animated:NO];
self.window.rootViewController = self.tabBarController;
// Clean up memory here... only if you don't need references to them
[sub release];
[nav release];
With setViewControllers:animated: you should probably include additional view controllers in the NSArray, otherwise you'll end up with a tab bar only containing one item!
[window addSubview:tabBarController.view]; would be right......
Rather than adding navigation controller using code..... you should add it from Interface Builder.... in interface builder remove the tabBarItem and add a navigationController on it and then set viewController for that navigation controller..........
create an outlet of tabBarController in appDelegate so that you can add it on window. Pleas do not forget to make connection between components in Interface Builder.
Thanks,
I am loading a Modal view controller using the following code in my RootViewController:
[self.navigationController presentModalViewController:accountViewController animated:YES];
In the accountViewController xib file, I have set a navigation bar. My MainWindow.xib and RootViewController.xib also have the navigation bar setup correctly. Additionally, my app delegate has setup the navigation controller (I assume) correctly:
UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
self.navigationController = aNavigationController;
[window addSubview:navigationController.view];
However, when I load my accountViewController the UINavigationBar is nowhere to be seen. Is it not possible to show a UINavigationBar in a modal view? I was planning to use it to hide the back button, and add a right button...
sha's answer is correct, but I'm giving my own answer to expand on it with a code example to make it clear.
You probably want something like:
- (void)showAccountViewController
{
AccountViewController* accountViewController = [[AccountViewController alloc] initWithNibName:#"AccountView" bundle:nil];
...
// Initialize properties of accountViewController
...
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:accountViewController];
[self.navigationController presentModalViewController:navController animated:YES];
[navController release];
[accountViewController release];
}
You need to push not viewController but navigationController that has viewController inside.
You can also set the presentation style in the Attribute Inspector to "Current Context". Modal View will not cover the Navigational Bar.
If you have a UINavigationController's UIViewController present a UITableViewController (TVC) modally, is there a way for the TVC to display the UINavigationBar of its parentViewController? Or, should I have it create a new UINavigationBar, item, buttons, etc. for the modal TVC?
I would just instantiate a UINavigationController right before you present your modal.
YourViewController *modalViewController = [[YourViewController alloc] initWithNibName:#"foo" bundle:nil]
UINavigationController *tmpNavController = [[UINavigationController alloc] initWithRootViewController:modalViewController];
[modalViewController release];
[self.navigationController presentModalViewController:tmpNavController animated:YES];
[tmpNavController release];
This is just back-of-the-envelope - I wouldn't copy and paste that code w/o a double-check!