swift - 在不使用 Storyboard Reference 的情况下转到另一个 Storyboard?
问题描述
我的应用程序中有一个按钮,单击时会发出警报,并且仅当用户单击“确定”时-我想将它们发送到另一个故事板。是否可以在 ViewController 中执行此操作?没有故事板参考?代码会是什么样子?
解决方案
根据您评论中更新的详细信息,您需要在情节提要中实例化您的 viewController 并手动执行导航,如下所示:
let alert = UIAlertController(title: "Alert!", message: "Do the thing", preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .default) { (action) in
let storyboard = UIStoryboard(name: "Bussturen", bundle: nil)
let viewController = storyboard.instantiateViewController(identifier: "BussturenViewController") as! BussturenViewController
//Do any more setup you might need to do for your viewController before navigation
self.navigationController?.pushViewController(viewController, animated: true)
}
alert.addAction(action)
self.present(alert, animated: true, completion: nil)
另请注意,这假设在故事板的身份检查器中,您将BussturenViewController
设置为“BussturenViewController”
推荐阅读
- javascript - filter(loaded =>!loaded) 是做什么的?
- android-studio - Flutter - 底部溢出 230 像素 Stak 布局
- javascript - React 中的 HTML/JSX 表单显示为 [object Object] 而不是数组中的实际值
- python - 有没有办法在数组中找到 n 个最远的向量?
- flowtype - 具有精确对象类型的流联合类型给出“[类型 1] 中缺少属性”
- ios - 在不同屏幕中导航时,应用程序会挂起一段时间
- animation - 为什么自动反转添加的动画会“搞砸”最终结果?
- python - Django:“ModelForm”对象没有属性
- python - Why doesn't fusing two loops together produce the same result as a nested loop?
- javascript - JavaScript addEventListener with Event and Binding a variable