推送新控制器时无法完成操作

Unable to complete the operation while pushing a new controller

我正在尝试导航到一个新控制器,但出现以下错误:

error The operation couldn’t be completed. (placesapi error 16.)

我尝试了几种方法,但错误仍然存​​在。

尝试 1

self.navigationController?.pushViewController(MainViewController(), animated: true)

尝试2

let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let mainViewController = storyBoard.instantiateViewController(withIdentifier: "mainViewControllerID") as! MainViewController
    self.present(mainViewController, animated: true, completion: nil)

控制器的标识符设置如图所示:

求解

清理我的项目并更改 navigationController 的名称后,如 Frankenstein 所述,导航正常。请注意,需要清洁。

您需要提供 story-board 名称而不是 view-controller 名称:

let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let mainViewController = storyBoard.instantiateViewController(withIdentifier: "mainViewControllerID") as! MainViewController

编辑:确保您的 Main.storyboard 文件有一个 ViewController,其 class 设置为 MainViewController,标识符设置为 "mainViewControllerID"