How to show cocoa touch framework storyboard screen?

I created a simple Cocoa touch structure with a storyboard. In my framework, I have a view manager MainViewController.swift. I created a new project with one view, imported my framework and tried to load the frame view manager, but I got a black screen. And I do not know why.

I tried the download framework with this code:

let frameworkScreen : UIViewController = MainViewController()
    self.presentViewController(frameworkScreen, animated: true, completion: nil)
+4
source share
3 answers

You need to load the view controller by creating it from the storyboard within the framework.

Here is how. Initial conditions first:

  • Let's say your framework is called Coolness.

  • Say your storyboard frame is called CoolnessStoryboard.storyboard.

  • , public, CoolnessViewController.

  • , CoolnessStoryboard , CoolnessViewController .

import Coolness , CoolnessViewController , :

let s = UIStoryboard (
    name: "CoolnessStoryboard", bundle: NSBundle(forClass: CoolnessViewController.self)
)
let vc = s.instantiateInitialViewController() as! UIViewController
self.presentViewController(vc, animated: true, completion: nil)

. . CoolnessViewController, . , . . ? , . ? . , (import Coolness), public ( ).

+26

. :

1 - "Messenger.framework"

2 - , "Messenger.Storyboard"

3- - UINavigationController ChatController.

, UIViewController:

- (void)presentChatController
{
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Messenger"
                                                         bundle:[NSBundle bundleForClass:ChatController.class]];

    ChatController *controller = [storyboard instantiateViewControllerWithIdentifier:@"Chat"];
    [self.navigationController pushViewController:controller animated:YES];
}

, .

+7

If your frame MyFrameworkname is the name of the storyboard Main, with a viewcontoller with the ID of the storyboardvc

if let urlString = NSBundle.mainBundle().pathForResource("MyFramework", ofType: "framework", inDirectory: "Frameworks") {
  let bundle = (NSBundle(URL: NSURL(fileURLWithPath: urlString)))
  let sb = UIStoryboard(name: "Main", bundle: bundle)
  let vc = sb.instantiateViewControllerWithIdentifier("vc")
  self.showViewController(vc, sender: nil)
}

I turned on the framework using cocoapods.

+2
source

All Articles