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
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.
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.
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
I have a login screen, and after auth, I have a tab bar controller with navigation controllers for each views, which I want to present.
Here is the code I use
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UITabBarController *obj=[storyboard instantiateViewControllerWithIdentifier:#"tabBar"];
self.navigationController.navigationBarHidden=NO;
[self.navigationController pushViewController:obj animated:YES];
Problem is The tab bar is not showing. Also, how can I specify to show the second view in the tabbar controller if I needed to?
I am using storyboard.
thanks for any help.
Instead of pushViewController, do a [self presentViewController:(UIViewController *) animated:(BOOL) completion:^(void)completion]
This will show the new view controller as full screen.
You can also create a named segue from the login screen to the tab controller with a modal transition style. You could then call [self perfromSegueWithIdentifier:#"YOUR SEGUE NAME" sender:nil];
To load the 2nd tab in the tab bar, you can do
[self.tabBarController setSelectedIndex:1]
to select the 2nd tab.