ios - 为什么我的 UIButton segue 的行为不像 UITableViewCell segue?

标签 ios swift uiviewcontroller segue

我正在尝试在 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/

相关文章:

ios - 使用私有(private) api 在 iOS 中检测启用的热点

ios - Framework ViewController View 未显示

ios - 对 NSMutableDictionary 进行排序

ios - 动态中的 Swift 自定义滑动 TableView 单元格问题

ios - 我在 IOS 中遇到字符串/服务器问题

ios - 通过动态 URL 发现从 NSDictionary 到 NSArray

swift - Xcode Swift 模板小驼峰式大小写

ios - 更改 UIAlertViewController 色调颜色

IOS 切换 View 和 Storyboard不起作用

ios - 与具有多个子 ViewController 的 ViewController 交互