My Question is simple.
I am using say 5 different storyboards along with 5 different core data models. Now in the app delegate I want to know which storyboard is loaded in memory so that I can set the models accordingly.
I am setting the storyboard under the deployment info in the project settings.
Try appDelegate.window.rootViewController.storyboard.
Try these lines of code...
NSString *mainStoryboard = [[NSBundle mainBundle] objectForInfoDictionaryKey:#"UIMainStoryboardFile"];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:mainStoryboard bundle:nil];
Do they help?
Related
It seems that Xcode 5 is not choosing to use my iPad storyboard for the iPad device even though i specified it.
This is how i told Xcode 5 to use iPad storyboard:
I went to project settings under General
Selected Devices: Universal
Then i clicked on iPad
And wrote MainStoryboard-iPad.storyboard in Main Interface
But for some reason even though i make changes to my MainStoryboard-iPad storyboard its not being showed when i try to run it on an iPad.
I only have two storyboards in my project
MainStoryboard-iPad.storyboard
and
MainStoryboard.storyboard
Any ideas what could be wrong here?
Oh by the way, when i selected Universal the first time i got a box asking me something about copying (i never read it that carefully). I just hit Yes. Not sure what that box actually did.
EDIT
Code that runs in my AppDelegate.m
- (void)applicationDidBecomeActive:(UIApplication *)application {
AppDelegate *app = [[UIApplication sharedApplication] delegate];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:#"mainStoryBoard"];
UINavigationController *nvc = (UINavigationController*)self.window.rootViewController;
app.window.rootViewController = ivc;
}
I just encountered this a while ago.
These are the steps you need to do:
make sure the "Deployment Info" -> Devices is "Universal"
Create a storyboard for iPad (e.g) MainStoryboard_iPad.storyboard
now go to your Infor.plist
add row for "Main storyboard file base name (iPad)" and use MainStoryboard_iPad as the value of the string
Now you are good to go!
Your code is overriding the default storyboard for the device type. You are grabbing MainStoryboard, instantiating a view controller from it and setting it as the root. This is normally handled by the storyboard itself. It uses the view controller that you have picked as the root. Try removing all of that code to manually set the storyboard.
Check this project on github for an example of storyboard switching without code: https://github.com/danielmackenzie/StoryboardSelection
Xcode project points to each storyboard per device type and the appropriate board is automatically chosen on launch.
You'll need an entry for the iPad in your app's info.plist
Look in your Supporting Files group for the info.plist for your app.
You'll see an entry for the iPhone's storyboard, but not one for the iPad.
The iPhone entry should look like this:
Main storyboard file base name
and it should have the name of your iPhone's storyboard (sans file extension) as the string value for it. Something like this:
iPhone-Storyboard
Add a new entry into the pList and enter this string as the key:
Main storyboard file base name (iPad)
Make sure the data type is string.
You can now select the iPad storyboard that you want from the app's General Settings on your Target.
I JUST ran into this as well and thought you'd like a clear explanation and solution.
Sometimes, Xcode is rather maddening, isn't it? Hope this helps.
// Override point for customization after application launch.
if (<your implementation>) {
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main"
bundle: nil];
YourViewController *yourController = (YourViewController *)[mainStoryboard
instantiateViewControllerWithIdentifier:#"YourViewControllerID"];
self.window.rootViewController = yourController;
}
return YES;
Your logic is not taking into account your device. AFAIK, there is no method that looks at your naming postfix ("-iPad") and automatically selects the right storyboard file.
To fix it, simply replace the call to instantiate your storyboard with some logic to pick the right one based on device.
UIStoryboard* storyboard;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard-iPad" bundle:nil];
} else
{
storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
}
I use this tutorial to achieve my custom UITabBarController: link
But I use storyboard instead of xibs. So some of method use this code below:
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:#"TabBarView" owner:self options:nil];
It is fair for xib but as I think not for storyboard.
This will work for u
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"StoryboardName" bundle:nil];
UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:#"ViewControllerName"];
Dont forget to give identifier to your viewcontroller inside the storyboard.
Note:- Make sure you have given ViewControllerWithIdentifier in storyboard.
I'm afraid storyboards are not well suited for this kind of task. There is no method for getting a specific view from a UIStoryboard instance.
In this case, I would recommend you to create a separate xib file with just the view you want to load on its own and use the code you gave to load it.
On a side note I would also not recommend using a library which has 3 years since the last commit, specially with iOS 7 out which breaks a lot of things.
I am working on a projects but have different screens. As there is more complexity I have told to create 2 projects then to marge it into 1 app.
So basically I have 2 projects lets name it as A and B. and both have 2 different storyboards.
Now I want these to projects to marge and when app fires storyboard from project A should show and there is button in project A and upon tapping it should show project B.
How can I achieve this. Can any buddy there help me..
I am not sure about this , but you can try this
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"YourStoryboardName" bundle:nil];
YourViewController *objViewController = [storyboard instantiateViewControllerWithIdentifier:#"YourViewController"];
[self.navigationController pushViewController:objViewController animated:YES];
I'm loading a view controller from a story board explicitly and have this code:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:#"InitialScreen"];
But am getting an error "'Storyboard () doesn't contain a view controller with identifier 'InitialScreen'"
Yet as can be seen from the screenshot, the view controller does have that identifier. I've used this identical way of loading controllers before successfully, but no idea why its not working this time. Any ideas what the issue could be?
I've just found the problem - its an issue with the simulator, I could find absolutely nothing wrong with my code and was 100% sure it was ok, when I've been in that situation in the past I usually find the culprit is Xcode itself. So even though I'd cleaned and rebuilt multiple times I decided to try resetting the contents in the simulator - and bingo it started working. I put it down to a bug in the simulator caching content and not updating to reflect changes made in IB.
Does your storyboard name match the name of the storyboard file you're trying to load the view controller from? Usually the storyboards are named something like MainStoryboard_iPhone
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
You should also check to be sure that there are no trailing spaces in the Storyboard ID textfield. Other than that everything else looks like it should work to me.
Does anyone have any examples? I've created iOS and Android modules for Titanium but haven't found any examples where people use Storyboard for visuals.
I know you can load nibs in modules using initWithNibName, check this SO answer out.
For storyboards specifically, I think that gets complicated since Storyboards define a whole navigation structure. I think you have two options, break down the specific windows in the storyboard into nib files, and then load those as needed, or open up the storyboard itself using code similar to this:
// You have to get the resource bundle first
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"YourStoryBoards" bundle:resourceBundle];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:#"yourViewController"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];
I have not tried this out, but I think the key is supplying the correct resource bundle, and then opening from a modal.