Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

610
Visualizações
Swift this class is not key value coding-compliant for the key Error

I m getting error Terminating app due to uncaught exception

'NSUnknownKeyException', reason: '[<KGM_IOS.NotEkle 0x7fcb5ee0cd40> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key notEkleTextView.'.

I have XIB called "notEkle" and inside of "notEkle" i have UITextView and XIB provider is ViewController. When i connect this text with controller i got this error. I load my XIB in controller like

let notEkleView: UIView =  NotEkle().loadNib() as UIView

I connect my text view with controller like

@IBOutlet weak var notEkleTextView: UITextView!

I dont have any problem before connect UITextview and controller.

let notEkleView: UIView =  NotEkle().loadNib() as UIView
extension UIView {
    func loadNib() -> UIView {
        let bundle = Bundle(for: type(of: self))
        let nibName = type(of: self).description().components(separatedBy: ".").last!
        let nib = UINib(nibName: nibName, bundle: bundle)
        return nib.instantiate(withOwner: self, options: nil).first as! UIView
    }
}
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

There are several steps to define a XIB and use it programmatically.

  1. First you need to create XIB file and the Swift file with the same name.

  2. Design as you need, then hook up the file's owner as the class name you have defined in Step 1.

  3. You need to define a common initializer method and override both initializers (with frame and coder).

  4. Hook up the whole view in XIB as IBOutlet in Swift class.

  5. Implement common initializer as follows:

private func commonInitializer() {
    Bundle.main.loadNibNamed("testView", owner:self, options: nil)
    addSubview(contentView)
    contentView.frame = self.bounds
    contentView.autoresizingMask = [.flexibleHeight,.flexibleWidth]
}
  1. Finally, you can drag a UIView to anywhere and set its class as this custom class.

For more details, you can check out this tutorial here

over 4 years ago · Santiago Trujillo Relatório

0

Everything was right for me but still I was getting this error, then I solved it by

  • Enabling the "Inherit module from Target" in the Identity Inspector. or
  • Giving the module(usually folder name/group name) in which it is present from the Identity Inspector under Custom Class
over 4 years ago · Santiago Trujillo Relatório

0

This class is not key value coding-compliant for the key

This happens when outlets are not connected correctly from the storyboard into a view controller.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda