User opens the app and the LoginViewController is shown, once they enter their details and press the login button a NSURLRequest is made and if the result is success the app needs to load the HomeViewController.
Everything is working except for loading the HomeViewController.
I have tried instantiating HomeViewController and:
[self presentViewController:Home animated:YES completion:NULL]
But it doesn't load the new controller, I'm not sure if I need to segue or perform some other type of modal request I'm not aware of.
I assume Home is the class of the HomeViewController?
It would be more of cocoa style when its name was HomeViewController.
self.homeViewController = [[Home alloc]init];
By doing so you would have to care for creating and layouting all the views that the controller contols. If you do that with Interface Builder then use
self.homeViewController = [[Home alloc] initWithXib:#"NameOfTheNibFileHere"]];
If your view controller is layouted in a storyboard, then give it an ID "HomeID" in this example) within the storyboard and load it via.
self.homeViewController = [storyboard instantiateViewControllerWithIdentifier:#"HomeID"];
If it is the root view controller of your storyboard, then I suggest to use
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
and go from there.
You can do this with a segue, but you don't want to trigger the segue from your login button - you need to do it programmatically. In Image Builder, go to the bottom of your login view and control-click on the yellow View Controller icon in the black bar and drag to your HomeViewController. Select "Replace" as the segue type and then give the segue an identifier (say "HomeSegue") as per usual.
Now, once your login has completed you can trigger the segue using
[self performSegueWithIdentifier:#"HomeSegue" sender:self];
If the login fails then you can stay on the login view controller and display an error as appropriate
Related
In my project I have existing side menu i.e swrevealviewcontrtoller to display right side menu.It is working correctly. I want to add second right menu in between the project using slideNavigationController. This is the screen shot of my storyboard. I can not touch existing base code and Before login page I want to add slideNavigationController to display another right sidemenubar.
i.e not my root view controller for that I referred these two links.SlideNavigationController,Solution for making rootviewcontroller
StoryBoard Image
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
LoginViewController *loginView = (LoginViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: #"Login"];
[loginView setModalPresentationStyle:UIModalTransitionStyleCrossDissolve];
SlideNavigationController * slideNavCtl = [[SlideNavigationController alloc] initWithRootViewController:loginView];
[self.window setRootViewController:slideNavCtl];
It is taking LoginViewController as root view controller.
As we are using SwrevealViewController at the first it contains modal segue so I am not able to display the right menu in login view controller. After adding that code in app delegate I am able to display right menu in loginpage but login page is the rootview but I want splash screen as a rootViewController. Using SlideNavigationController I want to display another right menu in login .
I have two storyboards in the same ios application.
Storyboard 1 is the login.storyboard.
Storybaord 2 is the processing.storyboard.
login.storyboard has the following scenes:
1) welcome
2) login
processing.storyboard has
1) start
2) images
3) description
4) finish
login.storyboard handles login whilst processing.storyboard creates and object for uploading.
My understanding of the stack is as follows:
Navigate from welcome to login gives:
1:[welcome]-[login.storyboard]
2:[login]-[login.storyboard]
after login I push the processing.storyboard using
- (void) pushStory: (NSString *) story {
UIStoryboard *settingsStoryboard = [UIStoryboard storyboardWithName:story bundle:nil];
UIViewController *initialSettingsVC = [settingsStoryboard instantiateInitialViewController];
initialSettingsVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:initialSettingsVC animated:YES completion:nil];
}
the stack should now be:
1:[welcome]
2:[login]
3:[start]
I might get to description in the workflow before I decide to click logout (available on each page), my stack at this point would be
1:[welcome]-[login.storyboard]
2:[login]-[login.storyboard]
3:[start]-[processing.storyboard]
4:[images]-[processing.storyboard]
5:[description]-[processing.storyboard]
logout should take me back to [welcome], my question is with the storyboards how would I clear the stack back to [welcome] and ensure the login.storyboard is current.
There's a gap in my knowledge here, as I've just gotten back into iphone dev after 6 years or so and not seen these before.
I had thought of just pushing login.storyboard onto the stack but that would just make the stack continue to grow instead of clearing it out
Use unwind segues.
Add this method in [welcome]:
-(IBAction)reset:(UIStoryboardSegue *)segue
{
NSLog(#"Back to Welcome");
}
In Interface Builder, create UIButtons in [start], [images] and [description] then link each of these buttons to the green "Exit" button of their respective viewControllers and select reset: in the pop-up menu that appears.
(See WWDC 2012 session video "Adopting Storyboards in Your App" for more details about unwind segues [starts at 38 minutes].)
You can pop back to any arbitrary point in the stack, for example
[self.navigationController popToRootViewControllerAnimated:YES]; // all the way back to the first view controller
[self.navigationController popToViewController:self.navigationController.viewControllers[1] animated:YES]; // back to the second view controller
[self.navigationController popViewControllerAnimated:YES]; // back to the previous view controller
This answer assumes that storyboard 1 has
navigation controller
welcome view controller
login view controller
and storyboard 2 has
navigation controller
start view controller
images view controller
description view controller
finish view controller
Note that the navigation controller in storyboard 2 is never actually instantiated but is needed so that the other view controllers in storyboard 2 can be connected by segues. When navigating from the login view controller to the start view controller the code should look similar to this
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"SecondStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"ControllerC"];
[self.navigationController pushViewController:vc animated:YES];
Note that this doesn't instantiate the initialViewController since that's the navigation controller, and we don't want another navigation controller. Instead, give the start view controller a Storyboard ID under the Identity inspector, and then instantiate the start view controller directly. After instantiating the start view controller, push it onto the existing navigation controller. You may want to hide the back button if you don't want the user to navigate back to the login view controller.
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"])
{
}
}
I am developing a basic which has a story board like this:
When the UIButton is pressed the URL is loaded. If the URL request is succesfull then I have the "Success" view (on on the right) opened.
It all works fine but I can't seem to get the navigation controller to appear on the Success view.
Could someone help me? Also, if the navigation can go on that view, how would I add a "back" button to take the user back to the main view?
Here is my code so far:
UIStoryboard * mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
NSLog(#"%#", status_code);
UIViewController *linkSuccess = [mainStoryboard instantiateViewControllerWithIdentifier:#"linkSuccess"];
[self presentViewController:linkSuccess
animated:YES
completion:NULL];
Peter
Control drag from the my app controller (the little yellow icon on the lower left in your screenshot) to the Success view controller and it should bring up the box asking you what kind of segue. Because this is a navigation controller you want a push segue. Click on the new arrow going from the my app controller to the success controller in the storyboard that represents your new segue and in the properties inspector give it a name, perhaps something like showSuccess
Then in your URL request successful code use this:
[self performSegueWithIdentifier:#"showSuccess" sender:self];
Alternatively, if you want to instantiate it yourself (as you have in the code above) you need to add it to the navigation controller. For example:
UIStoryboard * mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
NSLog(#"%#", status_code);
UIViewController *linkSuccess = [mainStoryboard instantiateViewControllerWithIdentifier:#"linkSuccess"];
[self.navigationController pushViewController:linkSuccess animated:YES];
You have to extending success view controller from 'My App' controller. Click on 'My App'view controller header, hold ctrl + click on trackpad + move it to success view controller.
Should be work
I just started to use Storyboard in Xcode. I have a starting view that has some buttons inside. Is there a way to load a special view when a button is clicked?
I only found this workaround:
-(IBAction)loadRegistration:(id)sender {
// load registration controller
UIStoryboard *storyboard = self.storyboard;
RegisterController *svc = [storyboard instantiateViewControllerWithIdentifier:#"RegisterController"];
[self presentViewController:svc animated:YES completion:nil];
}
You don't need any code to load a new view. You just control-drag from the button to the controller you want to present, and choose the segue type. If the controller with the button is in a navigation controller you can choose push or modal, if it's not, then you want to choose modal.
The way you did it seems ok. You can also connect the current View Controller to the one you want to present with a segue in the Interface Builder (ctrl + drag). When the button is tapped, you would call [self performSegueWithIdentifier:#"segue identifier"];. Of course, you set the id of the segue in the IB.
Even more simpler would be to connect the button with the new View Controller in IB (also ctrl+drag). This way you won't even need the IBAction.