【问题标题】:Unable to complete the operation while pushing a new controller推送新控制器时无法完成操作
【发布时间】:2020-05-22 05:46:36
【问题描述】:

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

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

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

尝试1

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

Attemp2

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

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

解决

在清理我的项目并更改 navigationController 的名称后,正如弗兰肯斯坦所说,导航工作正常。请注意,需要清洁。

【问题讨论】:

  • 你在使用任何谷歌 API 吗?

标签: swift xcode navigation


【解决方案1】:

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

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

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

【讨论】:

  • 我也尝试使用 Main 作为故事板文件 (Main.storyboard) 的名称,但它一直失败。我是否还需要在该文件中创建过渡?我的意思是通过拖动和选择显示(我是 iOS 新手,所以我不太了解导航概念)。先验地,我认为我在我的代码中创建了这个转换,但可能还需要在故事板文件中
  • 嘿,我已经清理了我的项目,现在它可以运行了。我会将您的正确标记为正确,因为您对故事板的名称也是正确的
猜你喜欢
  • 1970-01-01
  • 2012-12-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-27
  • 1970-01-01
  • 2014-04-13
  • 1970-01-01
相关资源
最近更新 更多