in my application the first view is an UIView with a couple of uilabel and an uibutton to do the login.
I would to show an uinavigationcontroller with a table after the login, so with the action of the button.
I know how to set up a working Navigation Controller starting with the Xcode Template but i dont know how to load this as a "Second View"
Any help?
You can add the view of the UINavigationController to the UIWindow and either let it obscure the first view or remove that view from the UIWindow. The navigationController won't have a back button to take you back to the first view (since it's stack doesn't include the first controller), so you'll need a custom button if you want to provide a way back.
- (IBAction) buttonPressed {
myNavigationController = [[UINavigationController alloc] initWithRootViewController:mySecondViewController];
[self.view.window addSubview:myNavigationController.view];
[self.view removeFromSuperview];
}
That's the direct answer to your question, however, if you simply want UINavigationController functionality but don't want to see the UINavigationBar on the first screen - check out:
Hiding the UINavigationBar only for the root UIViewController
Related
I am working on an application for IOS .I made a menu bar which contains buttons , menu bar should be on each page of application. I made many View controller scenes , I want the functionality like this : when i click on any button it should open a View controller scenes.
How to open a View controller scenes on click of button ? I don't want to add other existing View controller scenes on my current View controller scenes as a subview. I want to open other existing scenes independently.
You have to look into the following
Navigation controller
Tab bar controller custom implementation
Have you tried this, just replace YourViewController with the name of the .xib you would like to load.
YourViewController *yvc = [[YourViewController alloc] init];
[self presentViewController:yvc animated:YES completion:nil];
This goes inside your IBaction for the navigation button, fyi.
You need to look into UINavigationController or UITabBarController. There are other ways too. The navigation controller is the easiest. Apple documentation has everything you need.
1) Insert View :
ButtonView *buttonView = [[ButtonView alloc] initWithNibName:#"ButtonView" bundle:[NSBundle mainBundle]];
buttonView.view.frame = CGRectMake(yourFrame);
[self.view addSubview:buttonView.view];
2) Remove View :
[buttonView removeFromSuperview];
have two view controller(FirstViewController,sixViewController),i create a toolbar button in the navigation bar using interface builder,when i press the toolbar button it should direct me to sixViewcontroller,in the sixViewcontroller i have back button to return firstviewController with slide in animation,my toolbar name is Item.help need guys coz I'm still new for iOS.
UIViewController *viewController6 = [[sixViewController alloc]initWithNibName:#"FourthViewController" bundle:nil];
UIViewController *viewController5 = [[FifthViewController alloc]initWithNibName:#"FifthViewController" bundle:nil];
Sounds like you would be much better off using a NavigationController which handles placing the navigation bar and managing the viewController stack automatically.
The UINavigationController class reference is a good place to start
http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html
I have a problem dismissing a popover that was launched from the navigationItem of a UINavigationController. It seems that the navigation item which is inserted by the UINavigationController does not trigger dismissal of the UIPopoverController. Usually, when you tap outside a popover, it is dimissed. But when you tap on the navigation item, the popover is not dismissed. Worse, if you tap the button which triggers the popover, you'll get a second instance of the popover.
All of this is done using storyboards:
- Create a view, embed it into a UINavigationView so it gets a navigationItem on the top.
- Put a UIBarButtonItem into the navigationItem (left or right, doesn't matter for the initial view on the navigation stack).
- Define another view, and drag a segue from the UIBarButtonItem to this view.
- Set the segue to be popover.
Once the popover is open, I cannot dismiss it by tapping on the navigationItem. I cannot believe this "works as designed", so I suspect I missed out on somthing.
Although my goal is to program as little as possible (that's what storyboards are about, aren't they?), I thought about workarounds: The first workaround that came to my mind was to add a UITapGestureRecognizer to the navigationItem, which would dismiss the popover when it detected a tap on the navigationItem. Unfortunately, the navigationItem seems to not be UIVIew, so it lacks the addGestureRecognizer: method...
EDIT: Adding a UITapGesturerecognizer to self.navigationController.navigationBar is possible, but prevents any tap to reach the UIBarButtonItems on the navigationBar. Yes, I could have expected that.
Thanks a lot for help,
nobi
Here's the complete description for popovers in storyboards. Assuming your controller to appear in the popover is named MyPopupController, do this:
Define a segue from the main scene to the MyPopupController scene, using style Popover.
Add a property to MyPopupController.h
#property (weak, nonatomic) UIPopoverController *popover;
Synthesize the property in MyPopupController.m
#synthesize popover = _popover
In the prepareForSegue:sender: method of the main scene controller, set up the popoverproperty:
UIStoryboardPopoverSegue *ps = (UIStoryboardPopoverSegue *)segue;
MyPopupController *dc = ps.destinationViewController;
dc.popover = ps.popoverController;
In the viewWillAppear: method of MyPopupController, add the following code (don't forget [super viewWillAppear] as well):
self.popover.passThroughViews = nil;
You should be done now.
Thanks to Robert for the basic idea - I just had to find the correct place because presentPopoverFromBarButtonItem is not used when using storyboards. Note that putting (5) into viewDidLoad does not work.
Have fun coding!
https://stackoverflow.com/a/12874772/1455770
after presenting a popover from a bar button item, the popover has had its "passthroughViews" set to include the nav bar, so your taps don't register. Set the passthroughviews to nil straight after you present the popover. ie.
self.myPopoverController presentPopoverFromBarButtonItem:myBarButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
self.myPopoverController.passthroughViews = nil;// at this point the myPopoverController has had its pass through views set to include the whole nav bar. remove it.
There might be a better solution than this, but why not only add the UITapGestureRecognizer to the navBar whenever the popover is open? Once you tap the button to open the popover, add the TapGestureRecogniser to the navBar. Once you dismiss the popover, remove the TapGestureRecogniser from the navBar.
I've faced this problem recently and none of the solutions that I've seen around worked for me. Then after some research I've found out a way that works like a charm.
First you need to add the UIStoryboardPopoverSegue to your class.
#property (nonatomic, strong) UIStoryboardPopoverSegue *popoverSegue;
Synthesize it inside of the class implementation:
#synthesize popoverSegue;
Afterwards, inside of the function called by your button when pressed add the following code:
([[popoverSegue popoverController] isPopoverVisible]) ?
[self.popoverSegue.popoverController dismissPopoverAnimated: YES] :
[self performSegueWithIdentifier: #"popSegue" sender:nil];
Now you are almost ready. inside of the method
- (void) prepareForSegue:(UIStoryboard)segue sender:(id)sender add the following code:
if([[segue identifier] isEqualToString:#"popSegue"]){
self.popoverSegue = (UIStoryboardPopoverSegue*) segue;
if(viewPopoverController == nil){
viewController = [[UIViewController alloc] init];
viewPopoverController = [[UIPopoverController alloc] initWithContentViewController:viewController];
}
}
Now every time you press the button it will either show or dismiss your window, the window will also be dismissed if you press outside of the popover. I hope it can help someone.
I would like to combine UITableView and UINaviationController in an app but as a newbie most apps I've seen just send you straight to the results view (UITableView). But, I guess a "normal" search application does not assume you have the results on the first screen. There should be a search form on first screen with input fields and a button that triggers the search process and show some results and navigation.
So, I'm just trying to replicate this normal behaviour in my app. I've already made the search form (no navigation shown on it, of course) and a seperated View called "ListingViewController" with its related View and containing a UITableView and where I think I should add the Navigation...The next idea will be to make a DetailViewController and possibly and ListingMapController to show the listing in a GoogleMap.
So, where I'm stuck at is how to add this Navigation Controller ?
Some suggested me to add it in the SearchViewController delegate...
But I don't want a navigation on search form of course...
Some suggested me to open the Navigation controller modally...
But, I"m also planning at adding a Tab Bar to allow user to see other informations (like About,etc...) and with a modal Nav controller I don't know if they will still see the bottom Tabbar...
Any suggestions? What do you think is of best practices especially to avoid my app of being rejected by Apple?
Thx in advance for reading and helping!
Stephane
You could init the navigationController with your View Controller as the root view Controller. Then hide the navigationBar (if you need to). You would then add the navigationController.view as the subview. This will basically look like the original view controller. Then you can pushViewController: animated: to push the results view Controller.
So, for example in your AppDelegate (or in the proper view controller):
Create a property and ivar for a UINavigationController and hook up its outlets in interface builder. Then set your search controller as the root view controller for the nav bar, and add it as a subview.
MySearchViewController* searchController = [[MySearchViewController alloc] init];
self.myNavigationController = [[UINavigationController alloc] initWithRootController:searchController];
[searchController release];
self.myNavigationController.navigationBarHidden = YES;
[self.window addSubview:self.myNavigationController.view];
[self.window makeKeyAndVisible];
Then of course in your searchController, you would simply say:
ResultsViewController* myResultsViewController = [[MyResultsViewController alloc] init];
//You may want to create another init method and pass in some arguments like an array:
// [[MyResultsViewController alloc] initWithResults:results];
then push the viewController
//This is in your search controller class
[self.navigationController pushViewController:myResultsViewController Animated:YES];
[myResultsViewController release];
from the results viewController, to get back you pop the view controller off of the navigationController view controller's stack.
//In results view controller perhaps in some IBAction for a back button:
-(IBAction)backButtonPressed:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
I would like to show a Navigation Controller after clicking a button. Every tutorial assumes the navigation controller will be the first screen so it links it to the App Delegate, but App delegate only appears at MainWindow.xib.
How do you guys add a navigation controller to a view different than the MainWindow?
Thanks!
Here is some sample code to expand on Roger's answer. The following method is linked to some user interaction on the current view controller (to compose an email for example). This will give the compose view the navigation bar across the top instead of coding buttons inside your custom view.
-(void) composeButtonPushed: (id) sender {
ComposeViewController *controller = [[ComposeViewController alloc] initWithNibName:#"ComposeView" bundle:nil];
UINavigationController *composeNavController = [[UINavigationController alloc] initWithRootViewController:controller];
[self presentModalViewController:composeNavController animated:NO];
}
UINavigationController is to navigate a heirarchy of views with UIViewControllers. If you don't have a root UIViewController, it won't work (and doesn;t make sense). If you do have a UIViewController, you simply send a - (id)initWithRootViewController:(UIViewController *)rootViewController init message to a new navigation controller passing in your UIViewController.