如何将一个故事板添加到 iOS SDK?

huangapple go评论71阅读模式
英文:

How can I add a storyboard to an iOS SDK?

问题

I'm developing an iOS SDK. I'm designing a screen that will appear in some actions. But I want to design these screens in .xib or storyboard. How can I do that?

This is how I did it:

let storyBoard: UIStoryboard = UIStoryboard(name: "Test", bundle: nil)
let newViewController = storyBoard.instantiateViewController(withIdentifier: "TestViewController") as! TestViewController

controller.present(newViewController, animated: true, completion: nil)

This throws the error:

Thread 1: "Could not find a storyboard named 'Test' in bundle.

英文:

I'm developing an iOS SDK. I'm designing a screen that will appear in some actions. But I want to design these screens in .xib or storyboard. How can I do that?

This is how I did it:

let storyBoard: UIStoryboard = UIStoryboard(name: "Test", bundle: nil)
let newViewController = storyBoard.instantiateViewController(withIdentifier: "TestViewController") as! TestViewController

controller.present(newViewController, animated: true, completion: nil)

This throws the error:

>Thread 1: "Could not find a storyboard named 'Test' in bundle

答案1

得分: 1

storyboardBundleOrNil:: 包含故事板文件及其相关资源的 bundle。如果指定为 nil,此方法将在当前应用的主 bundle 中查找。

如果您正在构建一个 SDK,那么您的故事板不在主 bundle 中,您需要指定 bundle:

let storyBoard: UIStoryboard = UIStoryboard(name: "Test", bundle: Bundle(for: TestViewController.self))
英文:

> storyboardBundleOrNil:
> The bundle containing the storyboard file and its related resources. If you specify nil, this method looks in the main bundle of the current application.

If you're building an SDK, then your storyboard is not on the main bundle, you have to specify the bundle:

let storyBoard: UIStoryboard = UIStoryboard(name: "Test", bundle: Bundle(for: TestViewController.self)

huangapple
  • 本文由 发表于 2023年4月6日 22:06:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/75950456.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定