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

后端 未结 2 1092
天命终不由人
天命终不由人 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

提交回复
热议问题