【问题标题】:Storyboard doesn't contain a view controller with identifier 'goToC'故事板不包含标识符为“goToC”的视图控制器
【发布时间】:2017-12-05 02:15:57
【问题描述】:

我想通过点击一个按钮进入CameraViewController,然后对二维码进行拍照。 我不断收到此错误 谢谢大家的帮助 我在 Storyboard 中为每个 ViewController 提供了它的类型

import UIKit

class movieListViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    @IBOutlet weak var movieTableView: UITableView!



    var movie:[Movie] = [Movie]()
    var currentMovies:[Movie] = [Movie]()
    var counter = 0

    override func viewDidLoad() {
        super.viewDidLoad()

        movie = Helpers.downloadJson()
        self.movieTableView.reloadData()
        sort()

    }

    func sort() {
        movie.sort(by: { $0.releaseYear < $1.releaseYear })
        movieTableView.reloadData()

    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return movie.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "MovieCell") as! MovieCell

        cell.createCell(movie: movie[indexPath.row])

        return cell
    }

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let selectedMovie = movie[indexPath.row]
        performSegue(withIdentifier: "goToDetail", sender: selectedMovie)
    }

    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        let nextVC = segue.destination as! DetailViewController
        nextVC.movie = sender as! Movie
    }

    @IBAction func addTapped(_ sender: Any) {
        let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
        let nextView = storyBoard.instantiateViewController(withIdentifier: "goToC") as! CameraViewController
        self.present(nextView, animated: true, completion: nil)

    }

}

    CameraViewController:


    import UIKit
    import AVFoundation

    class CameraViewController: UIViewController, AVCaptureMetadataOutputObjectsDelegate {

        var captureSession: AVCaptureSession?
        var videoPreviewLayer: AVCaptureVideoPreviewLayer?
        var qrCodeFrameView: UIView?

        override func viewDidLoad() {
            super.viewDidLoad()

            let captureDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)

            do {
                let input = try AVCaptureDeviceInput(device: captureDevice)
                captureSession = AVCaptureSession()
                captureSession?.addInput(input)
            } catch {
                print(error)
                return
            }
            let captureMetaDataOutput = AVCaptureMetadataOutput()
            captureSession?.addOutput(captureMetaDataOutput)
            captureMetaDataOutput.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)
            captureMetaDataOutput.metadataObjectTypes = [AVMetadataObjectTypeQRCode]
            videoPreviewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
            videoPreviewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
            videoPreviewLayer?.frame = view.layer.bounds
            view.layer.addSublayer(videoPreviewLayer!)

            captureSession?.startRunning()

            qrCodeFrameView = UIView()

            if let newFrame = qrCodeFrameView {
                newFrame.layer.borderColor = UIColor.green.cgColor
                newFrame.layer.borderWidth = 2
                view.addSubview(newFrame)
                view.bringSubview(toFront: newFrame)
            }

        }

    }




    DetailViewController

    import UIKit

    class DetailViewController: UIViewController {
        @IBOutlet weak var movieImage: UIImageView!
        @IBOutlet weak var titleLbl: UILabel!
        @IBOutlet weak var releaseYearLbl: UILabel!
        @IBOutlet weak var ratingLbl: UILabel!

        var movie: Movie = Movie()

        override func viewDidLoad() {
            super.viewDidLoad()

            titleLbl.text = movie.title
            ratingLbl.text = "Rating: \(movie.rating) ⭐️"
            releaseYearLbl.text = "Release Year: \(movie.releaseYear)"

            movieImage.layer.cornerRadius = 5.0
            movieImage.clipsToBounds = true

            movieImage.sd_setImage(with: URL(string: movie.image))
        }

        @IBAction func backToList(_ sender: Any) {
            self.dismiss(animated: true, completion: nil)
        }


    }

【问题讨论】:

  • 你一定是把segue设置错了……
  • 检查 segue 是否正确,目标视图控制器是否与您希望的相同
  • 可能重复check this
  • 你还有其他从电影列表视图控制器启动的 segues 吗?
  • 具体检查从movieListViewControllerDetailViewController 的segue。我猜你是错误地在movieListViewControllerCamerViewController 之间切换。

标签: ios swift uitableview storyboard segue


【解决方案1】:

Xcode 8.2.1

我以为CameraViewController 在你的Main 故事板中。

Main 故事板中,首先选择相应viewController 顶部的黄色按钮,然后转到identity inspector -&gt; identity -&gt; Storyboard ID 输入您的视图控制器标识符goToC

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-21
    • 2020-06-28
    • 2023-03-09
    • 2015-05-18
    • 1970-01-01
    • 1970-01-01
    • 2016-01-04
    相关资源
    最近更新 更多