I am very very new to iOS programming / Objective C.
The flow of events I want to have happen is: user selects tab from tab bar view controller. Once VIEW A has been loaded it will open a modal window to get some information
VIEW A - (void)viewDidLoad
ModalYearPickerViewController *modalYearPickerViewController= [[ModalYearPickerViewController alloc] init];
[self presentViewController:modalYearPickerViewController animated:NO completion:nil];
I am trying to have my year picker view load up right away so the user can select a year from my picker (in VIEW B), then close the modal window after the value has been passed back to VIEW A.
Now, the fist view loads, then goes to a black screen automatically. I am unsure why as my view controller for modalYearPickerViewController has a picker etc on it.
Any tips or help loading a modal view controller programmatically would be greatly appreciated!
Thanks!
If you are using storyboards :
UIStoryboard *storyBoard = [self storyboard];
This will return the storyboard of your current view controller. I am assuming your View Controller A is also on your storyboard.
ModalYearPickerViewController *modalYearPickerViewController = [storyBoard instantiateViewControllerWithIdentifier:#"ModalYearPickerViewController"];
This will instantiate your view controller from the storyboard. But one other thing you have to do is set your view controllers storyboard id to ModalYearPickerViewController. You can set this right below where you set your custom view controller class in the storyboard.
[self presentViewController:modalYearPickerViewController animated:NO completion:nil];
and done.
If you have a xib file for that viewContrioller, it has to be loaded as well, to do that you have to call:
ModalYearPickerViewController *modalYearPickerViewController =
[[ModalYearPickerViewController alloc] initWithNibName:#"ModalYearPickerViewController" bundle:nil];
Related
There is problem in view hierarchy. Here is flow of my app.
When app starts View Controller "A" is Visible. After that storyboard "B" is loaded through "StoryBoard Reference (Push)" ,Where another navigation controller is present and Home screen is loaded. On Click of Menu button in Home screen Side panel is visible.
Now When i click on side panel menu items view Controller "B" is pushed. This View Controller is Pushed Under Home screen and is not Vsible.
Help View contoller is visible under Home controller. I want Help View Controller should come on top of Home controller.
I dont understand what issue is coming..
Any Help will be appreciated..
If you are pushing view controller from side panel shows in image, will never push because it is not in navigation controller.
the answer depends on how you showing your side menu but from assumptions
what you need to do is to set root view controller or keep reference of navigation controller and push from there
If you are presenting side menu then it is not on navigation controller so you should first dismiss this side menu and on the completion of it you should push new view controller (says B or Help). I am writing my code snippet that i am using in my project for demonstration,
- (IBAction)settingClick:(id)sender {
SettingViewController *svc = [self.storyboard instantiateViewControllerWithIdentifier:#"settingsScreen"];
[self dismissViewControllerAnimated:NO completion:^{
[self.vc.navigationController.navigationController pushViewController:svc animated:YES];
}];
}
Above method push setting view controller on current navigation controller after dismissing side menu
Now important thing is self.vc this is the object of previous viewcontroller (Home controller in your case i think) on which side menu was presented.
So my SideMenuViewController has a property like,
#property (nonatomic,strong) UIViewController *vc;
which i am setting with self from previous view controller (in your case from Home view controller) something like,
SideMenuViewController *smvc = [self.storyboard instantiateViewControllerWithIdentifier:#"sideMenu"];
smvc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:smvc animated:NO completion:^{
smvc.vc = self;
}];
And i have used [self.vc.navigationController.navigationController pushViewController:svc animated:YES]; i.e. two navigation controller to push because i have two navigation controller in my view hierarchy to push this new view controller.
You can manage that as per your setup that how many navigation controller you have !!
Hope this will help :)
After digging a lot, I found solution for this.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Home" bundle: nil];
RootController *someViewController = [storyboard instantiateViewControllerWithIdentifier:#"RootController"];
[self.navigationController pushViewController:someViewController animated:YES];
I have set another navigation controller as root ViewController of the window and it worked for me.
Thanks.
I added a Navigation Controller to my storyboard and it appears like so:
Now in the table view controller, I gave the TableViewController a storyboard id and class to a TableViewController Controller
When I run my app, I don't see the Navigation Bar at the top. This has been extremely frustrating and can't find a solution anywhere. PLEASE HELP
To get to the scene, someone clicks a button and this code runs and it goes to my Table View Controller:
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
LHFileBrowser *LHFileBrowser = [storyBoard instantiateViewControllerWithIdentifier:#"FileBrowser"];
[self.navigationController pushViewController:LHFileBrowser animated:YES];
[self presentViewController:LHFileBrowser animated:YES completion:nil];
The error is in your code.
If you want to (modally) present a view controller when the user presses a button, you need to present the navigation controller (which will contain the table view controller), not the table view controller itself.
Right now, you're presenting the view controller, which won't show it being embedded in a navigation controller.
Also, you're mixing up two different approaches, by trying to push a view controller onto a navigation controller stack, and also presenting the view controller.
Code Sample:
Here's what you apparently mean to do:
UIStoryboard *storyboard = self.storyboard;
UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:#"MyNavigationControllerID"];
LHFileBrowser *rootViewController = [navigationController topViewController];
// Configure your LHFileBrowser view controller here.
rootViewController.someProperty = ...;
// Modally present the embedded view controller
[self presentViewController:navigationController animated:YES completion:nil];
If you want to change the presentation or transition style, you can set those details in your storyboard.
You didn't explain why you had to programmatically add buttons, but Storyboard segues would have instantiated and presented an embedded view controller for you, without you having to have done it in code.
The more you can do in Storyboard, the less code you have to maintain, support, and update, and the more likely your app will still work properly when a new SDK is released.
Update:
The better way to do this is to let Storyboard do it for you, by adding a segue from the button to the navigation controller that you want to present.
Ok, I'm still pretty new; so, please bear with me.
I'm creating a custom app for a friend that displays a list of work orders in a table view. Clicking on a work order brings them to a detail view. In the detail view, there is a button that uses a push to present another screen called completion view. From the completion view, they click a button that uses the following code to present a nib for signature capture.
SigScreenViewController *sigScreenViewController=[[SigScreenViewController alloc] initWithNibName:#"ViewController_iPhone" bundle:nil];
[self presentViewController:sigScreenViewController animated:YES completion:nil];
The signature screen uses: https://github.com/jcmontiel/SignatureViewExample for capturing the signature and does it well. I have a button that completes the transaction and sends it back to the table view list.
My problem is that I cannot create a button that will return me to the completion view in the storyboard.
I've tried the following in a button:
[self dismissViewControllerAnimated:YES completion:nil];
or
[self.navigationController popViewControllerAnimated:YES];
I'm open for any suggestions on how I can do it.
Thanks in advance!
Have you tried having the UIViewControllers embedded in a navigation controller ?
Are you pushing from a UIViewController in UIStoryboard to a NIB file?
If so check out this sample project that pushes from storyboard to a NIB:
// in a navigation controller
// to load/push to new controller use this code
// this will be next screen
DetailsViewController *detailsViewController = [[DetailsViewController alloc ]init];
[self.navigationController pushViewController:detailsViewController animated:YES];
// to go back or pop controller use this
// now it will send back to parent screen
[self.navigationController popViewControllerAnimated:YES];
I'm new to xcode ios 7.
I've struggling a lot with navigation controls building app for iPhone ios7.
I don't want to use storyboard. I prefer to do it programmatically.
What i am trying to do.
I know how to create NavigationBar & Navigation Toolbar via AppDelegate.m
But if it's possible i don't want to do it, because let's assume i want in FirstViewController to show just simple button "Go to Second View Controller" (No Navigation Bar or Toolbar here).
And now in SecondViewController i want to create Navigation Toolbar (bottom) with 4 different tabs linking to ViewControllers!
But the trick is, i want to maintain different Navigation Bar (top) for every ViewController (as you can see in this screenshot).
Here is my Xcode Project File
And here is screenshot form Fancy app showing what i am trying to achieve.
Thanks a lot in advance!
Just to give you an idea, When you tap the button on your first view controller, you can create a UINavigationController and set your second view controller as its root view controller. This way, your first view controller remains no nav bar view and the second view controller holds a Navigation controller. Try something like below:
-(IBAction)goToSecondVC:(id)sender // An action for the button in your first VC
{
SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil]; //Init with second view controller
UINavigationController *secondNavVC = [[UINavigationController alloc] initWithRootViewController:secondVC]; // create a navigation controller and set the root as your second view controller
[self presentViewController:secondNavVC animated:YES completion:nil]; // and then present it with anim or no anim..
}
I'm trying to use a popover as an intermediary menu between my main view and a modal view controller. I can successfully present the Modal view controller from the popover by using the following code:
UIStoryboard *storyboardiPad = [UIStoryboard storyboardWithName:#"MainStoryboard_iPad" bundle:nil];
cbwEditControlPanel *editCP = [storyboardiPad instantiateViewControllerWithIdentifier:#"EditCP"];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:editCP];
[nav setToolbarHidden:NO];
[nav setModalPresentationStyle:UIModalPresentationFullScreen];
[nav setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentViewController:nav animated:YES completion:nil];
self.modalInPopover = NO;
The problem I'm running into is that when the EditCP modal view controller is dismissed, the main view controller never updates. I have a pagecontroller on the main view that should be updated to reflect the number of pages as set in the EditCP modal view controller, but for some reason the modal view controller being called from the popover prevents the main view controller from updating the pagecontroller. I've even tried calling the main view's "View Will Appear" method from the popover or modal view when they are dismissed, but even if the 'viewWillAppear' method is called the pageController will not update!
Any ideas what is preventing the pageController from updating? I even passed a reference to the pagecontroller to the modal view and tried to update it there, but it seems that from the time the popover is presented until it is dismissed, I cannot update the number of pages on the PageController.
Thank you!
So this is an old question but I also came across a similar problem recently when using a popover. My solution was to use an unwind segue to trigger my parent view to perform some action. In my case my parent view contains contact information and the popover contains a list of cites. All I wanted to do was to have the parent view update with the new city once the user selected it from the popover. So in my parent view I create my unwind function as follows:
In the .h:
- (IBAction)unwindToContactTVC:(UIStoryboardSegue *)unwindSegue;
In the .m:
- (IBAction)unwindToContactTVC:(UIStoryboardSegue *)unwindSegue
{
[self updateTableForOffice];
}
In the above .m file is where you would have the logic to do whatever it is you want to in the parent view. To connect this unwind segue go to the child view in the storyboard and control drag from the view icon to the exit icon. You should see a pop up with the name of your unwind segue.
Finally, give that unwind segue a name and then in the child controller in the viewWillDisappear() function call the segue as follows:
- (void)viewWillDisappear:(BOOL)animated
{
[self performSegueWithIdentifier:#"unwind-to-contact-tvc" sender:self];
}
I hope that helps. If someone has a better solution let me know.
Well, I half solved the problem. The only way to get an update function when the popover disappeared was to stop using Storyboards and programmatically present the popover, using the main view as the delegate. I then was able to update correctly inside the popoverControllerDidDismissPopover method.
However, I am still interested in finding a way to update the pageControl when the modal is dismissed, before the popover is dismissed.