标签:pac lse exe 参数 nav esb ide bsp view
俩个方法
1.
/// 指定字符串VC跳转,设置title func pushVcByVcNameAndTitle(vcName:String, vcTitleName:String = "", isHideBottomBar:Bool = false){ if let namespace = Bundle.main.infoDictionary?["CFBundleExecutable"]as? String{ let clsName = namespace + "." + vcName if let cls = NSClassFromString(clsName) as? UIViewController.Type{ let vc = cls.init() vc.title = vcTitleName self.navigationController?.pushViewController(vc, animated: true) } } }
2.
/// 根据字符串获得对应控制器,使用的时候as, 传递参数 func pushVcByVcNameAndTitle(vcName:String) -> UIViewController?{ if let namespace = Bundle.main.infoDictionary?["CFBundleExecutable"]as? String{ let clsName = namespace + "." + vcName if let cls = NSClassFromString(clsName) as? UIViewController.Type{ let vc = cls.init() return vc } } return nil }
3.使用 : 我这里是tableview使用的
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { //这里 VC需要传递参数进去的 var pushVc : UIViewController?
//具体VC 设置 vc的属性 if let vc1 = pushVcByVcNameAndTitle(vcName: vcNameArr[indexPath.section][indexPath.row]) as? JYWorksShowController{ vc1.title = titleArr[indexPath.section][indexPath.row] //vc1.arr = self.dataArr //vc1.title = vcTitleArr[index.row] pushVc = vc1 } //这是主页面看需求隐藏tabbar self.hidesBottomBarWhenPushed = true if let vc = pushVc{ self.navigationController?.pushViewController(vc, animated: true) }else{ //这里不需要指定控制器。设置VC的属性的。 pushVcByVcNameAndTitle(vcName: vcNameArr[indexPath.section][indexPath.row], vcTitleName: titleArr[indexPath.section][indexPath.row], isHideBottomBar: true) } //跳转打开,不然回到首页 没有tabbar self.hidesBottomBarWhenPushed = false }
标签:pac lse exe 参数 nav esb ide bsp view
原文地址:https://www.cnblogs.com/qingzZ/p/10069503.html