ios - 我想在 swift 4 中以编程方式从 uiviewcontroller 导航到 uitabbarcontroller?
问题描述
我想从一个控制器(不是 uitabbarcontroller 的一部分)导航到 uiviewcontroller(这是 uitabbarcontroller 的一部分)我怎样才能做到这一点?
解决方案
使用故事板转场
在 and之间设置 segueUIViewController
并UITabBarController
执行它。
以编程方式
UITabBarController
只需使用控制器呈现某些新实例
let tabBarController = // instantiate it (add controllers if needed)
present(tabBarController, animated: true)
从故事板实例化
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let instantiated = storyboard.instantiateViewController(withIdentifier: "identifier")
if let tabBarController = instantiated as? UITabBarController {
present(tabBarController, animated: true)
}
UITabBarController
nib 实例化方法的子类
class TabBarController: UITabBarController {
class func instantiate(with controllers: [UIViewController]) -> TabBarController {
let controller = TabBarController(nibName: "TabBarController", bundle: nil)
controller.viewControllers = controllers
return controller
}
}
用法(不要忘记设置UITabBarItem
每个控制器):
present(TabBarController.instantiate(with: controllers), animated: true)
推荐阅读
- python - 比较列相等时如何追加列
- scheme - 遍历 Racket 中的结构列表列表?
- r - 在 flexdashboard 中使用仪表工具时出错
- r - 如何生成一个列,其中每个条目都是来自其他列的元素列表?
- r - 闪亮的模块:处理按钮列表
- ffmpeg - ffmpeg 输出文件大小的增长速度快于电影长度的线性增长
- r - 如何从 modelsummary 包中的 msummary 的 lmer() 模型中提取拟合优度统计信息
- rxjs - 想用rx.js合并多个数据源,支持增删数据源
- reactjs - 用道具反应测试浅快照问题
- scala - 是否有工具可以解释 Scala 程序中每个符号的含义以及如何解析它?