【问题标题】:Segue from storyboard to .xib从情节提要转至 .xib
【发布时间】:2020-10-02 20:37:17
【问题描述】:

我有一个 storyboardViewController (UITableViewController),该表的 1 项是“USERS”(UIButton),但我需要将它与 .XIB 连接,这个 .XIB 在同一个项目中。

我不能在 UIButton 和 .XIB 之间做一个 segue。 请帮助我:D

【问题讨论】:

标签: swift xcode


【解决方案1】:

UIButton@IBAction 连接起来,并将以下代码添加到操作方法中,以呈现在.xib 文件中设置的新UIViewController

@IBAction func handleButtonAction(_ sender: UIButton) {
    let viewControllerInXib = ViewControllerInXib(nibName: "ViewControllerXibName", bundle: nil)
    present(viewControllerInXib, animated: true)
}

要通过UINavigationController 导航,您应该使用以下方法:

@IBAction func handleButtonAction(_ sender: UIButton) {
    let viewControllerInXib = ViewControllerInXib(nibName: "ViewControllerXibName", bundle: nil)
    if let navigationController = navigationController {
        navigationController.pushViewController(viewControllerInXib, animated: true)
    } else {
        print("Navigation controller unavailable! Use present method.")
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-23
    • 2012-02-13
    • 1970-01-01
    • 1970-01-01
    • 2020-06-02
    • 2017-04-06
    • 2013-11-10
    • 2012-12-18
    相关资源
    最近更新 更多