【问题标题】:'Storyboard (<UIStoryboard: 0x7b1800030960>) doesn't contain a view controller with identifier 'GroupProfileViewController'' [duplicate]'故事板(<UIStoryboard:0x7b1800030960>)不包含标识符为'GroupProfileViewController'的视图控制器' [重复]
【发布时间】:2020-06-28 08:10:43
【问题描述】:
fileprivate func showGroupProfile(_ item:HomescreenLongTapItem) {
    let vc = storyboard?.instantiateViewController(withIdentifier: "GroupProfileViewController") as! GroupProfileViewController
    present(vc, animated: true, completion: nil)
}

按下 HomescreenLongTap 中的图标后,我需要更改 VC,但我收到错误消息“Storyboard () 不包含标识符为“GroupProfileViewController”的视图控制器 我在代码中使用了 StoryboardID。 如何正确导航到下一个 ViewController?

【问题讨论】:

  • 试试this
  • 我投票结束这个问题,因为我在 9 年前问过同样的问题。一个简单的谷歌搜索就会找到正确的答案。

标签: swift storyboard viewcontroller


【解决方案1】:
  1. 确保设置了视图控制器的标识符,比如“GroupProfileViewController”
  2. 确保此代码在viewDidLoad()不是。如果有,请考虑在viewDidAppear() 中执行此操作

像这个例子一样展示代码:

if let storyboard = storyboard{
   let vc = storyboard.instantiateViewController(withIdentifier: "GroupProfileViewController") as! GroupProfileViewController
   self.present(vc, animated: true)
}

【讨论】:

    【解决方案2】:

    试试这样:

        if let vc = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(identifier: "GroupProfileViewController") as? GroupProfileViewController {
             present(vc, animated: true, completion: nil)
        }
    

    在故事板中:--> 在自定义类中给这个视图控制器类 GroupProfileViewController

    --> 身份 --> 故事板 ID (GroupProfileViewController) 也与类或您的愿望相同。

    【讨论】:

      猜你喜欢
      • 2017-12-05
      • 1970-01-01
      • 1970-01-01
      • 2015-02-21
      • 2023-03-09
      • 2015-05-18
      • 2012-07-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多