【发布时间】:2020-10-02 20:37:17
【问题描述】:
我有一个 storyboardViewController (UITableViewController),该表的 1 项是“USERS”(UIButton),但我需要将它与 .XIB 连接,这个 .XIB 在同一个项目中。
我不能在 UIButton 和 .XIB 之间做一个 segue。 请帮助我:D
【问题讨论】:
我有一个 storyboardViewController (UITableViewController),该表的 1 项是“USERS”(UIButton),但我需要将它与 .XIB 连接,这个 .XIB 在同一个项目中。
我不能在 UIButton 和 .XIB 之间做一个 segue。 请帮助我:D
【问题讨论】:
将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.")
}
}
【讨论】: