Going from a Storyboard to Nib and back again - ios

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];

Related

Not able to navigate to another UIViewController programmatically iOS

I am trying to navigate to "Home" view controller and for this I have written the following code in the ContainerViewController. But once the code executes, the application hangs and it show 100% CPU usage. Please help.
- (IBAction) home:(UIButton *)sender
{
HomeViewController *homeViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"HomeViewController"];
[self.navigationController pushViewController:homeViewController animated:YES];
//[self presentViewController:homeViewController animated:YES completion:nil];
}
I have a question for you
1-If You want to push SecondViewController on to FirstViewController then your code is good enough
2-If you have a containerview in firstViewController and you want to add SecondViewcontroller's view to firstViewController
then use this code
UIViewController*vc1 = [[test1 alloc]initWithNibName:#"SecondViewController" bundle:nil];
//add to the container vc which is self
[self addChildViewController:vc1];
//the entry view (will be removed from it superview later by the api)
[self.view addSubview:vc1.view];
I think you want an unwind segue here. In your first view controller add :
- (IBAction)unwindToFirstViewController:(UIStoryboardSegue*)sender
{
}
You then need to hook up each of your view controllers home button to the green Exit button at the bottom of the view controller, choosing the unwindToMainMenu option. This will then take you back to the first view controller when pressed.
Have you tried popping the current view?
navigationController?.popViewControllerAnimated(true)
or just popping to root?
navigationController?.popToRootViewControllerAnimated(true)
or setting a new stack?
navigationController?.setViewControllers(homeViewController, animated: true)
The code is in Swift but it would work the same in ObjectiveC

UIViewController Not able to redirect

Here is my problem. I had a UITableViewcontroller to which UINavigation controller is Embedded. To UITableviewController I had Add screen and an edit screen. Add screen is working perfectly. When I click on the records on the table view cell it is able to redirect to the edit page (detailed view). When I hit on Submit button the page is not navigating to the tableview cell. Here is the below error.
Warning: Attempt to present on whose view is not in the window hierarchy!
Here is the code I was trying for navigation.
UINavigationController *questionnaireNavController = [self.storyboard instantiateViewControllerWithIdentifier:#"DLProjectsTasksubtasks"];
[questionnaireNavController setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
DLProjectsTasksubtasks *qvc = (DLProjectsTasksubtasks *)[questionnaireNavController topViewController];
[qvc.tableView reloadData];
[self presentViewController:questionnaireNavController animated:YES completion:nil];
[self dismissViewControllerAnimated:YES completion:nil];
Between I was using a Segue for transfering the data from tableview data to Edit Screen
I think your segue is being pushed on the navigation controller rather than being presented modally. So you have two options, either change the segue in your storyboard to be modal and use the dismissViewControllerAnimated:YES completion: or keep it the way it is and use popViewControllerAnimated: on your navigation controller.
[self.navigationController popViewControllerAnimated:YES];
For passing the data to the previous page you can either pass a reference of the previous view controller OR accessing it through your navigationController.viewControllers. Index n-2 will be your previous view controller (n is the count of viewControllers).

iOS Storyboard UIViewController switch back & forth

The basic design of app storyboard goes like this:
Top Level#1
Navigation Controller --> View Controller (Front) contains button "Show Master"
Next Level#2
Navigation Controller --> View Controller (Master) --> push --> View Controller (Detail)
When I run the app in simulator, Front View Controller page appears.
Requirement: On "Show Master" button click, I wanted the control focused to Master. When something done here, either show Detail view Controller or swing back to Front view Controller. How to code this from Front.M and Master.M.
Setup: iOS 6.x, XCode 5.x
Note: Below code exists in Front.M but it does not work, brings up Master page in black
vwMaster *vc = [[vwMaster alloc] init];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];
Any thought?
It looks like you're most of the way there, but that vwMaster has no layout information associated with it. One way to provide this would be to create a .xib file with the same name as your view controller class (i.e. vwMaster.xib) and set the xib file's owner to vwMaster. Your existing code should then work.
It seems like you're using Storyboard, however, in which case you have several options:
The easiest option. In Storyboard, ctrl-drag from the button in the Front view controller to the Master view controller. select a modal segue type.
Create a modal segue between the Front and Master view controllers in Storyboard by ctrl-dragging between them, give the segue an identifier (e.g. "vwMaster") in the attributes inspector and trigger the segue in code:
[self performSegueWithIdentifier:#"vwMaster" sender:self];
Give the vwMaster view controller itself an identifier in the identity inspector in storyboard and present that as you were before:
vwMaster *vc = (vwMaster *)[self.storyboard instantiateViewControllerWithIdentifier:#"vwMaster"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];
Regardless of the route you choose, you're likely to want use the delegate pattern to dismiss your view controller. For this and more, I suggest you read the relevant apple Docs:
https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html
if you use navigationcontroller y u no use push and pop instead presenting viewController?
Thanks knellr.
I have been playing with different flows. I am able to goto view by calling
[self performSegueWithIdentifier:#"name" sender:self] - provided name'm.
Also have strong code handling - in cases where data to be passed out
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
//NSLog(#"prepareForSegue: %#", segue.identifier);
if ([[segue identifier] isEqualToString:#"name"])
{
}
}

Having issues displaying modal view programmatically

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];

From XIB to Storyboard

I got an app with a storyboard and one window in .xib.
From the storyboard to the .xib i move in that way:
ShowDreamNIBController *detailViewController = [[ShowDreamNIBController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:detailViewController animated:nil];
How can i move back from the .xib to the storyboard?
And one more question. Can i send some information when move to the .xib from storyboard? Like i do it throught segues in prepareForSegue method
UPD I got answer about closing .xib. Need answer about sending information.
you can get back to your storyboard by simply dismissing the modal view controller.
Like this:
- (IBAction)backPressed:(id)sender {
[self dismissModalViewControllerAnimated:YES];
}
You should put this method in your ShowDreamNIBController.
As for the second question, you can send back information to the view controller that presented the modal view controller by getting reference to it using delegation.
EDIT:
To "send information to the XIB" do you mean that you want to set information to the view controller that you want to present? If yes, than use this when you present the modal controller:
ShowDreamNIBController *detailViewController = [[ShowDreamNIBController alloc]initWithNibName:nil bundle:nil];
[detailViewController setSomething: something];
[detailViewController setAnotherThing: anotherThing];
[self presentModalViewController:detailViewController animated:nil];
I hope this helps.

Resources