在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
根据类名来实例化对象,比如,要根据 let controllerName="SpainAppProto."+xibName // xibName 形如 XXViewController var classType: AnyObject.Type=NSClassFromString(controllerName) var nsobjectype : UIViewController.Type = classType as UIViewController.Type var viewController: UIViewController = nsobjectype(nibName: xibName, bundle: nil)
但是 在根据 UIViewController.self 来实例化的时候就要稍微转化下 var x: String = m.debugDescription // m为 UIViewController.self x = x.stringByReplacingOccurrencesOfString("Optional(", withString: "") x = x.stringByReplacingOccurrencesOfString(")", withString: "") let anyClass: AnyClass = NSClassFromString(x) let viewControllerClass: UIViewController.Type = anyClass as UIViewController.Type let viewController = viewControllerClass()
|
请发表评论