ios - 为 iOS 应用程序创建了一个下一步按钮...单击时出现 SIGABRT 错误

标签 ios swift

我正在尝试构建一个基于 GoogleMaps 的应用程序。当用户在 MapViewController 上时,我希望他们能够在 map 上选择一个位置并单击右上角的下一步。这样做应该会将他们带到另一个屏幕,其中包含位置描述 (HomeViewController)。我坚持执行“下一步”按钮。我当前的按钮代码如下所示...

override func viewDidLoad()
{
....

navigationItem.rightBarButtonItem = UIBarButtonItem(title:"Next", style: .plain, target: self, action: #selector(MapViewController.next as (MapViewController) -> () -> ()))

}

     func next()
     {
        print("next")
        if let navController = self.navigationController, let viewController = self.storyboard?.instantiateViewController(withIdentifier: "indentfier") as? HomeViewController{
            navController.pushViewController(viewController, animated: true)
        }
     }

我一开始只用 print("next") 运行它并且它起作用了(即,它只是在控制台上打印了“next”)。当我添加带有推送的第二行时,当我单击“下一步”时应用程序开始崩溃。我的应用程序委托(delegate)上也出现了 SIGABRT 错误。

注:HomeViewController其实就是首页;这是用户在 map 之前已经看到 4-5 个屏幕的前一个屏幕。我基本上希望他们在点击“下一步”时返回几屏到主页。

如有任何帮助,我们将不胜感激。谢谢。

最佳答案

替换

navigationItem.rightBarButtonItem = UIBarButtonItem(title:"Next", style: .plain, target: self, action: #selector(self.next(_:)))

@objc func next(_ bar:UIBarButtonItem) {

}

关于ios - 为 iOS 应用程序创建了一个下一步按钮...单击时出现 SIGABRT 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53399692/

相关文章:

iphone - 向 iPhone 上的 SharePoint 声明身份验证

objective-c - 在 iOS 中高效绘制边框文本

javascript - IOS 设备中的浏览器不会在后台自动播放声音

ios - 'RLMException',原因 : 'Realm accessed from incorrect thread.'

ios - 如何终止正在进行的 SCNTransaction?

ios - swift ,NSOperationQueue.mainQueue() : update data in operation during operation is running?

ios - 传递参数以将项目发布到 Facebook

swift - barButtonItem 中 UIKit 的 "pushViewController"的 SwiftUI 的替代方案是什么

swift - 是否应该在 if 语句中使用返回 bool 值的函数?

ios - 如何自动调整包含多行 UIButton 的 UITableViewCell 的高度?