我正在尝试在 UIViewController 之间创建 Segue,但从 UITableViewCell 和 UIButton 创建 Segue 时遇到一些困难。
当我通过 Storyboard从 UITableViewCell 到 UIViewController 创建显示详细信息时,它工作得很好,并且显示了后退按钮。但是,当我尝试创建从 UIButton 到 UIViewController 的显示详细信息时,它不会注册导航堆栈,并且会在没有后退按钮的情况下以模态方式呈现屏幕。
如何成功地从 UIButton 到 View Controller 显示详细信息?我是 iOS 新手,无法确定为什么 UIButton segue 的行为与 UITableViewCell segue 的行为不同。
预先感谢您的帮助!
最佳答案
不要通过按钮操作手动连接转场。
假设具有此按钮的 viewController 是导航 Controller 的 Root View Controller
@IBAction func myButtonTapped(_ sender: Any) {
let vc = self.storyboard!.instantiateViewController(withIdentifier: "YOUR STORYBOARD IDENTIFIER GOE HERE")
self.show(vc, sender: self)
}
如果您想转到选项卡栏 Controller 的选项卡,则必须指定其索引。我认为你可以在 Storyboard 中设置它,但我只是将 0 放在左侧,然后它们按顺序向上。因此,在下面的示例中,我想通过模式转换转到选项卡栏 Controller 的第二个选项卡。我假设您可以像上面的示例一样在此处使用 show 我只是从未这样做过。
let tbc = self.storyboard!.instantiateViewController(withIdentifier: "MyTabController") as! UITabBarController
tbc.selectedIndex = 1 // this is 2nd tab index.. start at 0
tbc.modalPresentationStyle = .overCurrentContext
tbc.modalTransitionStyle = .coverVertical
self.present(tbc, animated: true, completion: { finished in
// you can also do some completion stuff in here if you require it.
// self.view.removeFromSuperview()
// self.navigationController?.navigationBar.removeFromSuperview()
})
关于ios - 为什么我的 UIButton segue 的行为不像 UITableViewCell segue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42476042/