I created a workspace and added two projects in Xcode workspace. One new and one existing. I want to access a storyboard of an existing project within a tap of a button in new project. Can I do that?
Existing project is linked with a lot of libraries and one of them is Tapku library. It works fine, but I want to have a new project and some buttons there, that when I tap a button I access an existing projects storyboard and then work with that so called application.
thank you.
This is what I tried to do:
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Main_iPad" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:#"LoginView"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];
and I have error:
Could not find a storyboard named 'Main_iPad' in bundle NSBundle "somePath/Application1.app (loaded)
This storyboard is in Application2 Project.
Related
I have two ios app one variant of the app is for the teachers and second version is for the students.Student version is live from the last two year on the app store.This version is non-ARC project .Now developed the teacher variant of the app .this version is using the storyboard and have the ARC.
My problem is that in the student version application is tabbar based and tabbar is declared in the app delegate .where as in the teacher version the application is based on heavily customised uinavigation controller like the side slide in menu ;which is declared in app delegate too.Now my problem is how can i combine these two project into one iPhone app.
Both teacher and students can be identify based upon the login.
I would try to re-work the student version into a storyboard (a separate one from the teachers version) and update it to ARC. Then, base on the login results (student or teacher), load the appropriate storyboard. So after you have the results of the login, you could do something like this:
UIStoryboard *storyBoard;
if (isStudent) {
storyBoard = [UIStoryboard storyboardWithName:#"MainStoryboard_student" bundle:nil];
}
else {
NSLog(#"teacher!");
storyBoard = [UIStoryboard storyboardWithName:#"MainStoryboard_teacher" bundle:nil];
}
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];
In order to make sure your app will replace the one in the store, make sure you keep the same bundle ID for the new combined app as you had for the student version currently in the store.
If you do not want to convert the student version files to ARC, you can convert the project to ARC, but flag the student classes that have not been converted to arc with the -fno-objc-arc flag
Basically, click on the project file, select your target, select the Build Phases tab, and for each of the old project files that do not use ARC, add -fno-objc-arc in the Compiler Flags field in the Compile Sources section.
If both teachers and students can be identified at the login stage, to solve this problem you most likely would need create a unified login page (root view controller) in your AppDelegate. Then after the user logins you determine what part of app would be more appropriate and show the next view controller embedded in UINavigationController or UITabBarController.
you can can make student project compatible to ARC by adding compiler flag -fno-objc-arc to all class files of student project.
remove auto loading of storyboard from the project settings, in AppDelegate define the logic for loading the rootview.
if (isStudent) {
UIViewController *rootViewController = [[UIViewController alloc] init];//whatever you appdelegate code for student is
[self.window setRootViewController:rootViewController];
}
else {
NSLog(#"teacher!");
UIStoryboard *storyBoard;
storyBoard = [UIStoryboard storyboardWithName:#"MainStoryboard_teacher" bundle:nil];
UIViewController *initViewController = [storyBoard instantiateInitialViewController];
[self.window setRootViewController:initViewController];
}
I am new to iOS, started working on static libraries.
I have a main project and a static library project. I have added my library projects header and lib.a in the main project. I am able to call library project's methods from main project. But library project has a storyboard named: LibStory.storyboard while main project has storyboard: MainStory.storyboard.
When I start my app view starts from MainStory.storyboard then I have to call my library project and start LibStory.storyboard. When I start storyboard of lib project, I get this error:
Warning: Attempt to present on whose view is not in the window hierarchy!
LibStoryBViewController is in lib project. Do I need to add "LibStory.storyboard" in main project, I did that too still not working.
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"LibStory" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:#"te"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];
This is the code in lib project to call storyboard. Please suggest me how to solve this?
I have two different but related projects. Parent project A has a storyboard. Child project B, which (in theory) extends the functionality of A, needs to instantiate A's main storyboard in its AppDelegate. In my xcode workspace, I've included parent A within child project B, as a linked project and I can see all the files. I am using the following code in application:didFinishLaunchingWithOptions:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"iPhone.storyboard" bundle:[NSBundle mainBundle]];
MainViewController *vc = (MainViewController *)[storyboard instantiateInitialViewController];
_window.rootViewController = vc;
[self.window makeKeyAndVisible];
The code fails at runtime at the storyboardWithName line, I assume because iPhone.storyboard is not available immediately within B, and it doesn't know to look for it within A. The actual storyboard file is located in a different folder outside child project B's project folder on disk.
It has nothing to do with B and A. Files in the project can be located anywhere. Your error is at runtime. It has to do with the app you are building and running. Think about what this line says:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"iPhone.storyboard" bundle:[NSBundle mainBundle]];
So you are claiming here that there is a storyboard called iPhone.storyboard inside this app's main bundle. But there isn't. The app is building and you aren't doing anything to cause the storyboard to be copied into the app's bundle as part of that process. That's what you need to do.
To get the storyboard to be in the main bundle, add it to this app's Copy Bundle Resources build phase.
(Now, of course, there may be other problems, e.g. if classes referred to in this storyboard are not also part of this app. But that's not what your question was.)
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];
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.