问题
Now, I have a workspace which have two project inside, one is call "ProjectOne" and the other is "ProjectTwo" as follow:
They have a storyboard respectively and now I want to connect two storyboard by pressing the "To Project Two" as follow:
but when I click the button, it show
"Terminating app due to uncaught exception 'NSInvalidArgumentException', >reason: 'Could not find a storyboard named 'two' in bundle NSBundle 8C6A5FDC9E06/ProjectOne.app> (loaded)'"
Is it possible to do that? I seeking the method for a few days but also no idea...
回答1:
You need to use the complete names of the storyboard you are including if your storyboard is in another project/module - this means including the bundle name. Please see the image below for how you would set this up in your storyboard. I have created an example setup with ProjectOne and ProjectTwo the same as your project setup.
The key is the information you put in the Storyboard reference. You need to include the bundle name as well! Just for reference I have included a link to Adding a Storyboard Reference
EDIT
While this works it leads to issues later on as you start to build your storyboard out with various scenes which are backed by view controllers, which now have to be linked to both project targets. More importantly this relationship is hidden in the project's configuration details. A better way for this to work would be to take advantage of the workspace and add a shared folder for the resources that are used by both projects.
Next add the shared folder to the workspace at the same level as ProjectOne and ProjectTwo. Now add a reference to the shared folder to each project by dragging it on to the project files(xcodeproj). This will add the folder to the projects target for you.
Now each project contains a reference to the shared folder, the sharing relationship is now explicitly shown within the project navigator.
回答2:
1.You can add both storyboard's Target Membership like this:
2.Change the name of your source files in Project two
to avoid collision,
check their Target Membership to Project one
,configure these changes to storyboard two.
3.The AppDelegate
file of Project two
should be leave unchanged.
回答3:
This was a solution I found for referencing a pod from a project - you can expose the bundle from the pod(or other project in your case), and then access it when you need to. It may also be worth mentioning that methods you want to access should be public.
static var bundle:NSBundle {
let podBundle = NSBundle(forClass: thisViewController.self)
let bundleURL = podBundle.URLForResource("myPod", withExtension: "bundle")
return NSBundle(URL: bundleURL!)!
}
来源:https://stackoverflow.com/questions/36783325/using-a-storyboard-reference-to-a-storyboard-in-a-different-project-bundle-appea