UIStoryboard open from another UIStoryboard - ios

I have a problem with calling one UIStoryboard from the second. My first Storyboard - Main, second - Management. When you click UIButton no action occurs. My source code:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Management" bundle:[NSBundle mainBundle]];
UIViewController *yourViewController = [storyboard instantiateViewControllerWithIdentifier:#"Management"];
[self.navigationController pushViewController:yourViewController animated:YES];

There are so many reasons may be here.
1. You might forgot to setup IBAction outlet to your UIButton
2. Storyboard names may not match you specify in your code
3. [storyboard instantiateViewControllerWithIdentifier:#"Management"]; are you sure you specified the same Storyboard ID for this controller?
4. In order to check all these suggestions it's enough just to set breakpoint on first line of your code and try to reproduce the situation.

Many wrong things can happen in that code.
First of all be sure that your action is well connected, put a breakpoint in your action to see if that is being called.
Second be sure that the storyboard name is correct, put a breakpoint after storyboard and check if it isn't nil (po storyboard in the debug console).
Second be sure that the "Management.storyboard" has a ViewController with the identifier "Management". So put a breakpoint after yourViewController to check if it is nil (po yourViewController in the debugger console).
Finally be sure that the view controller where you have the action is inside the navigation controller. So check if self.navigationController is nil (po self.navigationController in the debugger console after you stopped in the action's code)

Need replace old code by this.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Management" bundle:[NSBundle mainBundle]];
UIViewController *yourViewController = [storyboard instantiateViewControllerWithIdentifier:#"ManagementIDS"];
[self presentViewController:yourViewController animated:YES completion:nil];

If you prefer doing it in interface builder than in code:
You can now create a storyboard reference in interface builder. That means you can link a storyboard from another storyboard. Target must be ios9.
https://developer.apple.com/library/prerelease/watchos/recipes/xcode_help-IB_storyboard/Chapters/AddSBReference.html#//apple_ref/doc/uid/TP40014225-CH49-SW1
check 19:00
https://developer.apple.com/videos/wwdc/2015/?id=407

Related

iOS switch view in a navigation controller from the app delegate

I'm trying to switch to another view in my navigation controller when the application didRecieveRemoteNotification is triggered.
Here is my current code:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
ConvViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:#"chatConversation"];
[(UINavigationController*)self.window.rootViewController pushViewController:ivc animated:NO];
For some reason i get (lldb) error on the second line.
Any ideas what I'm doing wrong?
Edit
I'm using storyboard segue identifier: chatConv
to my Custom Class: ConvViewController and my custom class has a Storyboard ID: chatConversation
Here is my Storyboard:
chatConversation should be a ViewController in MainStoryboard.storyboard. In MainStoryboard.storyboard, select your chatConversation ViewController. In the Identities panel, make sure your custom class is set to ChatViewController.
instantiateViewControllerWithIdentifier takes a view controller identifier not a segue identifier. So something like:
[storyboard instantiateViewControllerWithIdentifier:#"convViewController"];

Unable to pushViewController iOS

I am using storyboard in my app, :
I have Button in my View, On click of button i want to navigate to new View
But when i click on button nothing happens,
Here is my Code:
- (IBAction)JoinClicked:(id)sender{
JoinWithViewController *detail_view_controller = [[JoinWithViewController alloc] initWithNibName:#"JoinWithViewController" bundle:nil];
[self.navigationController pushViewController:detail_view_controller animated:YES];
}
Where i am doing mistake , please help.
Thanks in advance.
Set storyboard id of view controller in story board in identity inspector
Make a reference to your storyboard like
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
then to your controller
YourController *vc = [storyboard instantiateViewControllerWithIdentifier:#"YourController"];// storyboardId
[self.navigationController pushViewController:vc animated:YES];
and you can also make segue and do
[self performSegueWithIdentifier:#"YourSegueIdentifier" sender:sender/nil];
use this one :
- (IBAction)JoinClicked:(id)sender{
[self performSegueWithIdentifier: #"JoinWithIdentifier" sender: self];
}
and add segue in storyborad like
Make an identifier for your push-segue in storyboard.
then use
[self performSegueWithIdentifier:#"YourSegueIdentifier" sender:nil];
When using story boards you should use segues for as much navigation as possible.
Your code seems fine, please verify your outlets correctly configured or not in xib or storyboard.
Edit:
You are using storyboard and wants the xib file to get pushed onto your view controller if I am not wrong, you can drag another view controller in storyboard and name it JoinWithViewController and push using segue on button click. That is much easier than what your trying to do here.

How to get out of a UIStoryboard initialized in code

I have a main container controller that initializes child view controllers.
I'm trying to learn to use UIStoryboards tho and I'm stumped as to how to get out of a storyboard.
Here's the flow:
Once I get to the end of a storyboard's scenes, how should I get out of storyboard and back to my container controller?
Should I keep a pointer to the storyboard? What would I do with it?
Should I keep a pointer to the initial view controller (which is the one I explicitly add as child)? It's .view won't be on screen at the end so I don't know what I would do with that either.
Try looping through the childViewControllers
for (UIViewController *vc in self.childViewControllers) {
// do something
}
What do you mean "out of a storyboard". You don't need to save a pointer to your storyboard as self.storyboard should work in most cases. If you use a UINavigationController as your entry point in your storyboard with your initial view controller as it's root view, all you have to do to get back to your initial controller is
[self.navigationController popToRootViewControllerAnimated:YES];
Also, you can get a reference to your storyboard like this as well:
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];

Storyboard UITabBaar, initiate two different views from button

I've created a storyboard that has a UITabbarController all is working well but now I want to add some logic that determines which viewcontroller a particular tabbar button will display.
Example... if a customer has a valid subscription display viewcontroller one, if no subscription display viewcontroller two.
Is this possible using storyboards, I've looked at UITabBarDelegate and prepareForSegue but struggling to piece this together?
Are there any examples of how to do this sort of thing using StoryBoards?
Many thanks
You can set it like this:
if(hasSubscription)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
ViewController1* subsection = [storyboard instantiateViewControllerWithIdentifier:#"ViewController1"];
ViewController2* subsection1 = [storyboard instantiateViewControllerWithIdentifier:#"ViewController2"];
[(UITabBarController*)self.window.rootViewController setViewControllers:[NSArray arrayWithObjects:subsection,subsection1, nil]];
}
If you want to add rootviewController according to the subscription then above answer given by soryngod is good one.
But if you want to open viewControllers after rootviewcontroller loaded, then at tabBarButton press perform following code:-
before this code, add yours viewControllerONE and viewControllerTWO to the rootViewController by segues as shown: . And give each segue an identifier in AttributeInspector, example "one" for viewControllerONE and "two" for viewControllerTWO.
then at tabBarButton action do the following:-
if(subscription)
[self performSegueWithIdentifier:#"one" sender:self];
else
[self performSegueWithIdentifier:#"two" sender:self];

How do I change "initwithNibName" in storyboard?

I want to change below code with storyboard with Xcode 4.2.
UIViewController * example = [[ExampleViewController alloc] initWithNibName:#"ExampleViewController" bundle:nil];
Now ExampleViewController.xib file exist.
but I want to make it with storyboard.
please help me.
(I'm not good at English. Sorry)
The UIStoryboard class is your friend:
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"mystoryboard"
bundle:nil];
UIViewController* vc = [sb instantiateViewControllerWithIdentifier:#"ExampleViewController"];
If it is still in its own xib file, then you don't change anything.
If you've moved everything into a storyboard, then you wouldn't often need to do this as you'd link between view controllers using segues.
If neither of the above are true, i.e. your view controller is on the storyboard but no segue connects to it, then you want UIStoryboard's instantiateViewControllerWithIdentifier: method described in the documentation. You have to set the identifier in the storyboard for this to work.

Resources