swift中使用NSClassFromString

2018-07-18  本文已影响7人  超级卡布达

      控制器名称 = 项目名称+.+控制器名称

        let vcStr ="SwiftTest."+ "ViewControll"

        let vc  = (NSClassFromString(vcStr) as! UIViewController.Type).init()

        self.navigationController?.pushViewController(vc, animated: true)


同理

let cellName = NSStringFromClass(SwiftTableViewCell.classForCoder())

 控制器名称 =项目名称+.+控制器名称

cellName = 项目名称.SwiftTableViewCell

所以想要拿到控制器名称 就需要切割cellName字符咯

cellName.components(separatedBy:".")

上一篇 下一篇

猜你喜欢

热点阅读