0

I just want to Jump from a ViewController to another using the code

    btn_routh.addTarget(self, action: #selector(self.goToPoiDetail), for: .touchUpInside)

    @objc open func goToPoiDetail() {

    self.present(PoiDetailViewController(), animated: true, completion: nil)
}

But When I click the btn_routh button, error appeared

*** Terminating app due to uncaught exception 'NSUnknownKeyException',
    reason: '[<OMOT.PoiDetailViewController 0x7fb269f1e010> 
    setValue:forUndefinedKey:]: this class is not key value coding-compliant 
    for the key addressLabel.'

But When I write

    print("print")

in the goToPoiDetail function , it prints well, so I think the problem is at the jumping sentence

in other place

btn_cate.addTarget(self, action: #selector(self.showSubMenu), for: .touchUpInside)

click btn_cate button works well.

The big difference from current ViewController to other ViewControllers is there is a custom View in ViewController, and the custom view use xib to build the interface of view. But without the jumping action , the custom view shows well.

Below is the code of my custom view where has a field "addressLabel" which shows in error warning

import UIKit

class PoiDetailView: UIView {
    @IBOutlet weak var categoryLabel: UILabel!
    @IBOutlet weak var introLabel: UILabel!
    @IBOutlet weak var addressLabel: UILabel!
    @IBOutlet weak var distanceLabel: UILabel!
    @IBOutlet weak var closeButton: UIButton!
    @IBOutlet weak var imageView: UIImageView!
    @IBOutlet var containView: UIView!
    var action:(()->Void)?

    var category:String = ""{
        didSet{
            categoryLabel.text = category
        }
    }
    var intro:String = ""{
        didSet{
            introLabel.text = intro
        }
    }
    var address:String = ""{
        didSet{
            addressLabel.text = address
        }
    }
    var distance:String = ""{
        didSet{
            distanceLabel.text = distance
        }
    }
    var imageUrl:String = ""{
        didSet{
            ImageLoader.sharedLoader.imageForUrl(urlString: imageUrl){
                image,url in
                print("load image")
                self.imageView.image = image
            }
        }
    }
    var imageAsset:String = ""{
        didSet{
            imageView = UIImageView(image: UIImage(named: imageAsset))
        }
    }

    func setImage(data:Data){
        print("\(#function)")
        imageView.image = UIImage(data: data)
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupXib()
    }
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setupXib()
    }
    func setupXib(){
        let view = Bundle.main.loadNibNamed("PoiDetailView", owner: self, options: nil)?.first as! UIView
        view.autoresizingMask = [.flexibleHeight,.flexibleWidth]
        addSubview(view)
    }


    @IBAction func closeDetail(_ sender: UIButton) {
        isHidden = true
    }

}

Where is the problem? How can I jump from this ViewController owned a view from Xib.

Bugs
  • 4,491
  • 9
  • 32
  • 41
周雪静
  • 153
  • 1
  • 3
  • 10

1 Answers1

0

Check the IBOutletConnection of your addressLabel.enter image description here

better, disconnect the layout connection you have made and connect the label again. You're probably referring to a non-existent IBOutlet or IBAction. Hope it will help.

Soumen
  • 2,070
  • 21
  • 25