0

I am trying to turn on Segue by pressing a button. Before I added this code it worked but after adding the code (code that triggers a video by clicking on a button) the code crashes my application with the following error:

due to uncaught exception 'NSUnknownKeyException reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key fatB.

I searched for the error and I understand that its mean that Xcode cant find some name (fatB) But I can't figure the rest out.

Below is my code:

viewcontroller1 code:

import UIKit

class ViewController: UIViewController {
    @IBAction func movieB(_ sender: Any) {
        performSegue(withIdentifier: "firstsegue", sender: self)
    }

    @IBOutlet weak var winnerLabel: UILabel!
}

viewcontroller2 code:

import UIKit
import AVKit
import AVFoundation

class ViewController2: UIViewController {

    func forbutton(name : String, type : String)  {
        func viewDidAppear(_ animated: Bool) {
            super.viewDidAppear(animated)
            playVideo(name: name, type: type)
        }
    }

    private func playVideo(name : String, type : String) {
        guard let path = Bundle.main.path(forResource: "\(name)", ofType:"\(type)") else {
            debugPrint("video not found")
            return
        }
        let player = AVPlayer(url: URL(fileURLWithPath: path))
        let playerController = AVPlayerViewController()
        playerController.player = player
        present(playerController, animated: true) {
            player.play()
        }
    }        

    @IBAction func fatB(_ sender: Any) {
        forbutton(name: "fatB", type: "mp4")
    }

    @IBAction func coderB(_ sender: Any) {
        forbutton(name: "birdC", type: "mp4")
    }

    @IBAction func clashB(_ sender: Any) {
        forbutton(name: "clash", type: "mp4")
    }
}
Anton Belousov
  • 1,140
  • 15
  • 34
  • `viewDidAppear` is nested in another method. Move it to the top level of the class. – vadian May 18 '18 at 11:59
  • The issue is that the method doesn't get parameters and I need different parameters for each button, am I able to do that? –  May 18 '18 at 12:03
  • `viewDidAppear` is called by the framework, don't call it yourself. If you want to pass parameters Implement `prepare(for segue` in the first view controller. – vadian May 18 '18 at 12:08
  • The problem is solved but the videos don't is this because the reason you specified? –  May 18 '18 at 12:43

2 Answers2

1

check connections inspector. there is an IBOutlet with named fatB. remove it from there

It may be an UIButton

Enea Dume
  • 3,014
  • 3
  • 21
  • 36
  • It's one of the necessary video playing buttons (how can i replace him?) –  May 18 '18 at 12:20
0

It may be because:

1) You have removed a IBOutlet from your code but not from Controller's scene in Storyboard.

2) You may have changed the name of your IBOutlet reference variable.

Please check your Controller's scene in Storyboard and remove the unused IBOutlet reference or update it with the new reference variable name.

Dheeraj D
  • 4,386
  • 4
  • 20
  • 34