【发布时间】:2018-10-07 12:55:04
【问题描述】:
使用 storyBoard 展示 ViewController: 如果 newViewController 在 StoryBoard 中。我们可以使用以下方法呈现它。
let storyboard = UIStoryboard(name: "AViewController"), bundle: UIBundle.main)
let newViewcontroller = storyboard.instantiateInitialViewController() as? AViewController
self.present(newViewcontroller, animated: false, completion: nil)
是否可以呈现不在storyBoard中但其父viewcontroller有storyboard的ViewController
我以编程方式创建了一个 B 视图控制器(没有 StoryBoard),现在我想展示 BViewController,它应该使用 AViewController StoryBoard?
class AViewController : UIViewController
{
//this class is in storyboard which is generic design that I want to use it in different ways.
}
class BViewController : AViewController
{
....//
}
e.g.
self.present(BViewController(), animated: false, completion: nil)?
当我展示 BViewcontroller 时,它会为来自超类的参数抛出 nil。
【问题讨论】:
-
按照您在问题中显示的方式进行操作有什么问题?
-
当你有类似的 viewcontroller 有小的改动时。你必须创建不同的视图控制器
标签: ios swift iphone uiviewcontroller reusability