Cannot instantiate UIView from nib. “warning: could not load any Objective-C class information”

后端 未结 2 1091
天命终不由人
天命终不由人 2021-01-14 22:33

I get \"could not load any Objective-C class information. This will significantly reduce the quality of type information available.\" warning in the console while initializi

相关标签:
2条回答
  • 2021-01-14 23:10

    This seems like you are going the long way round instantiating a view. You have a view of class SystemMessage which instantiates a nib of name SystemMessage and then inserts that as a view :/

    The simplest way to do this is to set the root view in your Xib to be of type SystemMessage

    Then you connect your outlets to the view that you just gave the right type

    This means that you can lose have your code and end up with

    import UIKit
    
    @IBDesignable
    class SystemMessage: UIView {
    
      @IBOutlet weak var lbl_message: UILabel!
    
      static func loadViewFromNib() -> SystemMessage {
        return NSBundle(forClass: self).loadNibNamed("SystemMessage", owner: nil, options: nil).first as! SystemMessage
      }
    
    }
    

    This just gives you an easy way to instantiate your view from code with SystemMessage.loadViewFromNib(). File's Owner is probably being set incorrectly in this instance

    0 讨论(0)
  • 2021-01-14 23:11

    Found the solution. It all comes to understanding of how xibs work.

    What I did was that I set class for both view and File's Owner and connected all the outlets from the View rather than from the File's owner.

    0 讨论(0)
提交回复
热议问题