Load UISplitViewController programmatically from another Storyboard - ios

Currently I am using two iPad storyboards in my project.
The first storyboard has a Login screen and a tableview controller. I want to call the second storyboard from the first storyboard tableview controller, when the cell is clicked. Normally it's easy, but here the second story board has a UISplitViewController.
MainSVC *baseView = [[MainSVC alloc] init]; //UISplitViewController
UIStoryboard *storyBoard=[UIStoryboard storyboardWithName:#"Mail_iPad" bundle:nil]; //Second Storyboard
baseView =[storyBoard instantiateViewControllerWithIdentifier:#"MainSVC"]; //MainSVC = Storyboard Name
[self presentViewController:baseView animated:YES completion:nil];
This code is not working. I searched in google, but couldn't find the best solution.
How can I call second storyboard splitview controller programmatically?

Use this code. This should be work. !
UIStoryboard *storyBoard=[UIStoryboard storyboardWithName:#"Mail_iPad" bundle:nil];
UISplitViewController *split = [storyBoard instantiateViewControllerWithIdentifier:#"MainSVC"];
self.view.window.rootViewController = split;

Do not allocate another instance of split view controller. It should be done like this
UIStoryboard *storyBoard=[UIStoryboard storyboardWithName:#"Mail_iPad" bundle:nil]; //Second Storyboard
MainSVC *baseView =(MainSVC *)[storyBoard instantiateViewControllerWithIdentifier:#"MainSVC"]; //MainSVC = Storyboard Name
[self presentViewController:baseView animated:YES completion:nil];

Related

Connect StoryBoard Button with Programmatically build UITabBarController

i build two project
Story Board -> Login Screen
Programmatically -> UITabBarController
both are different Projects but managed With MVC structure
now i want to connect StoryBoard Button with Programmatically build UITabBarController
Please Help me to solve this Problem.
To create a view controller:
UIViewController * vc = [[UIViewController alloc] init];
To call a view controller (must be called from within another viewcontroller):
[self presentViewController:vc animated:YES completion:nil];
For one, use nil rather than null.
Loading a view controller from the storyboard:
NSString * storyboardName = #"MainStoryboard";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:#"IDENTIFIER_OF_YOUR_VIEWCONTROLLER"];
[self presentViewController:vc animated:YES completion:nil];
Identifier of your view controller is either equal to the class name of your view controller, or a Storyboard ID that you can assign in the identity inspector of your storyboard.

How to navigate to a view controller on a new storyboard file in objective-c

I got a source code for an existing app. throughout the app the developer didn't use storyboard for the user interface but rather he used interface builder xib files. As a new developer, i don't know how to develop iOS apps in xcode using xib files for viewcontrollers, i learnt the storyboard way. Now I want to add more screens to the apps source code, i created a new storyboard file to define my new screens, how do I navigate to the entry point of this new storyboard from a button action i defined in one of the xib files so that i can easily implement my features.
while searching i got some suggestions like this one
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"newStoryboard_iPhone" bundle:nil];
MyNewViewController *myVC = (MyNewViewController *)[storyboard instantiateViewControllerWithIdentifier:#"myViewCont"];
but i dont think i understand how to implement this even if this can be in a button IBAction method. and besides subsequent navigations would be segues through the view controllers i define in the new storyboard
It's right suggestion.
You should get storyboard object by its name. Then you should create your viewController using [storyboard instantiateViewControllerWithIdentifier:#"..."];
Then you may navigate to your new VC using appropriate navigation method. For example:
[self.navigationController pushViewController:vc animated:YES]
ViewController identifier you should set in Interface Builder under section "Identity Inspector" in field "Storyboard ID".
That code you should place in IBAction method. But better would be to extract it in separate method. Something like this:
- (IBAction)buttonPressed:(UIButton *)sender {
[self navigateToMyNewViewController];
}
- (void)navigateToMyNewViewController {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"myNewStoryboard" bundle:nil];
MyNewViewController *myNewVC = (MyNewViewController *)[storyboard instantiateViewControllerWithIdentifier:#"MyNewViewController"];
[self.navigationController pushViewController:myNewVC animated:YES];
}
Navigation from MyNewViewController your can implement as you want. It may be segues.
MyNewViewController *myVC = [self.storyboard instantiateViewControllerWithIdentifier:#"YOUR_VC_NAME_HERE"];
This will instantiate your ViewController, from here you can present it like so
[self presentViewController:myVC animated:YES completion:nil]
The image shows where you set the storyboard name that you're referring to
Try This it's working for me ,
Use below line of code :
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main"bundle:nil];
LoginViewController *loginVC = (LoginViewController*)[storyboard instantiateViewControllerWithIdentifier:#"LoginViewController"];
[self.navigationController pushViewController:loginVC animated:YES];
We need to set storyboard id as per mention in below,
you can navigate one storyboard to another storybord:
first you import your viewcontroller class to appdelegate.h
AppDelegate *appDelegateTemp = [[UIApplication sharedApplication]delegate];
appDelegateTemp.window.rootViewController = [[UIStoryboard storyboardWithName:#"storyboard_name" bundle:[NSBundle mainBundle]] instantiateInitialViewController];
Like the way you use storyboard, use
MainViewController *mainVC = [[MainViewController alloc] initWithNibName:#"MainViewController" bundle:nil]
[self.navigationController pushViewController:mainVC animated:YES];

storyboard, self presentViewController, iOS 6, blank screen

I am using storyboards, I have one viewcontroller and on click I need to show another view controller modally. I am trying using this code
[self presentViewController:zoomV animated:YES completion:NULL];
I am coming up with a blank screen.
This is how I create
zViewController *zoomV = [[zViewController alloc] init];
[self presentViewController:zoomV animated:YES completion:NULL];
I tried researching this and some answers revolve around using storyboards and not having a rootviewcontroller associated. So what I have is in the initial scene I have a navigationController, and from there I drag to another Viewcontroller a relationship which defines it as a rootViewcontroller. Is that sufficient ? or is this irrelevant?
Since you have your zViewController in your storyboard, you should instantiate your zViewController using UIStoryboard instantiateViewControllerWithIdentifier:.
In your first view controller, instead of creating the zViewController using alloc/init do this, of course setting an identifier for your zViewController in your storyboard.
zViewController *zoomV = [self.storyboard instantiateViewControllerWithIdentifier:#"yourIdentifier"];
[self presentViewController:zoomV
animated:YES
completion:NULL];
Also you could accomplish the same using a segue and executing it directly, without the need of instantiating the zViewController, but is up to you.
As a second(small) comment, do not name classes starting with lowercase in ObjC :).
You may refer below snippet for story board:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
AddNameViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:#"AddNameViewController.m"];
[sfvc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentViewController:sfvc animated:YES completion:nil];

Initiating a segue from uiview or uivewcontroller that is not on storyboard

How can I initiate segue from a custom UIView or custom UIViewController that is not on Storyboard? - they are created programmatically inside a parent UIViewController.
Although the destination UIViewController is on the storyboard.
Then just do it the old fashioned way. Instantiate it and present it modally or just push it if you are in a navigation controller. Hope this helps.
EDIT:
You can talk about segue only if it is in the storyboard. If Your source View Controller is not in it, you just present the next one as I said. You can instantiate your destination view controller from the storyboard:
MyViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:#"MyViewController"];
[self presentViewController:controller animated:YES];
From this point you will be "back in the storyboard" so you can perform segues in the destination View Controller.
First give storyboard id. Select the view controller than write a identifier(Storyboard ID)
Secondly, just open your .m file then write belove codes.
UIStoryboard * st = [UIStoryboard storyboardWithName:#"nameOfStoryboard" bundle:nil];
MyViewController *viewController = [st instantiateViewControllerWithIdentifier:#"YourStoryboardID"];
[self.navigationController pushViewController:viewController animated:YES];
Last line of code. Might also be
[self presentModalViewController:viewController animated:YES];

how to transit to a view controller

I made a view controller A in storyboard and linked with other view controller. Now I have another view controller B and I want to write a method that can transit from B to A. How can I do this?
There is a segue to controller A in storyboard.
And controller B is loaded from another view I created programmatically so I can't set a segue in storyboard.
Since you are using storyboard. This is more accurate, try this:
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:#"YOUR VIEW CONTROLLER"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];
But be sure to name your view's identifier otherwise it will crash and wont work.
Then when you want to dimiss the view:
[self dismissModalViewControllerAnimated:YES];

Resources