来自Storyboard的子类ViewController [英] Subclass ViewController from Storyboard

查看:128
本文介绍了来自Storyboard的子类ViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Storyboard中创建了ViewController,我正在使用

I created ViewController in Storyboard and I am using

instantiateViewControllerWithIdentifier:

加载它。但我需要将此VC作为基类,并使用3-4个子类来更改其属性。

to load it. But I need to have this VC as base class and use 3-4 subclasses to change its properties.

如何使用 instantiateViewControllerWithIdentifier 获取我的子类的实例?

How can I get an instance of my subclass with instantiateViewControllerWithIdentifier?

推荐答案

Swift 3中的@Bhagyesh版本

class func instantiateFromSuperclassStoryboard() -> SubclassViewController {
    let stroryboard = UIStoryboard(name: "Main", bundle: nil)
    let controller = stroryboard.instantiateViewController(withIdentifier: "BaseViewController")
    object_setClass(controller, SubclassViewController.self)

    return controller as! SubclassViewController
}

这篇关于来自Storyboard的子类ViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆