【问题标题】:Modal VC not open (Swift)模态 VC 未打开 (Swift)
【发布时间】:2018-01-05 09:05:47
【问题描述】:

如何让 VC 也出现

我试过这个,但 ms 加载干净,没有按钮和 TextView。

let modalViewController = ClipboardViewController()
modalViewController.modalPresentationStyle = .overCurrentContext
present(modalViewController, animated: true, completion: nil)

示例:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    if indexPath.row == 0 {
        self.navigationController!.pushViewController(self.storyboard!.instantiateViewController(withIdentifier: "ViewController") as UIViewController, animated: true)
    } else if indexPath.row == 1 {
    // VC with animation
    } else if indexPath.row == 2 {
        self.navigationController!.pushViewController(self.storyboard!.instantiateViewController(withIdentifier: "Favorite") as UIViewController, animated: true)
    } else if indexPath.row == 3 {
        self.navigationController!.pushViewController(self.storyboard!.instantiateViewController(withIdentifier: "Settings") as UIViewController, animated: true)
    }
}

【问题讨论】:

  • 正如您所期待的按钮等,我假设您已经在情节提要或 xib 文件中设置了视图控制器。如果是这种情况,那么您不要使用此行 let modalViewController = ClipboardViewController() 创建它,否则您将创建一个没有任何控件设置的程序(如您所见)。您需要从 storyboard/xib 实例化它或创建一个 segue 并执行它。

标签: ios swift xcode modalviewcontroller


【解决方案1】:
    let modalViewController = self.storyboard?.instantiateViewController(withIdentifier: "ClipboardViewController ID") as? ClipboardViewController
    modalViewController?.modalPresentationStyle = .overCurrentContext
    self.present(modalViewController!, animated: true, completion: nil)

【讨论】:

    猜你喜欢
    • 2019-05-29
    • 2016-09-17
    • 2019-01-09
    • 1970-01-01
    • 2021-09-19
    • 1970-01-01
    • 2012-06-27
    • 2017-08-24
    • 1970-01-01
    相关资源
    最近更新 更多