'故事板 (<UIStoryboard: 0x7b1800030960>) 不包含标识符为 'GroupProfileViewController' 的视图控制器'

'Storyboard (<UIStoryboard: 0x7b1800030960>) doesn't contain a view controller with identifier 'GroupProfileViewController''

fileprivate func showGroupProfile(_ item:HomescreenLongTapItem) {
    let vc = storyboard?.instantiateViewController(withIdentifier: "GroupProfileViewController") as! GroupProfileViewController
    present(vc, animated: true, completion: nil)
}

我需要在按下 HomescreenLongTap 中的图标后更改 VC,但我收到错误“Storyboard () doesn't contain a view controller with identifier 'GroupProfileViewController' 我在代码中使用了 StoryboardID。 我怎样才能正确导航到下一个 ViewController?

这样试试:

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

在故事板中:--> 在自定义 class 中给出此 viewcontroller class GroupProfileViewController

--> identity --> Storyboard ID (GroupProfileViewController) 也给出与 class 相同的名称或您的意愿。

  1. 确保设置 viewcontroller 的标识符,假设 "GroupProfileViewController"
  2. 确保此代码在 viewDidLoad() 不是 。如果有,请考虑在 viewDidAppear()
  3. 中执行此操作

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

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