@IBDesignable error: IB Designables: Failed to update auto layout status: Interface Builder Cocoa Touch Tool crashed

前端 未结 22 2026
终归单人心
终归单人心 2020-12-02 04:45

I have a very simple subclass of UITextView that adds the "Placeholder" functionality that you can find native to the Text Field object. Here is my code for the su

相关标签:
22条回答
  • 2020-12-02 04:51

    In my case, I was doing the next in the initWithFrame/initWithCoder methods to create the view:

    className = NSStringFromClass([self class]);
    self.view = [[[NSBundle mainBundle] loadNibNamed:className owner:self options:nil] firstObject];
    

    It looks like I was Not supposed to use the Main Bundle, but instead the bundle of the class. So I replaced that code for the following and it worked:

    bundle = [NSBundle bundleForClass:[self class]];
    className = NSStringFromClass([self class]);
    self.view = [[bundle loadNibNamed:className owner:self options:nil] firstObject];
    

    I thought maybe this might help somebody.

    0 讨论(0)
  • 2020-12-02 04:54

    When i debugged this i found out there are some classes which are modifying UI. Typically marquelabel which is a subclass of UILabel or any other class subclassing UIView and drawing ui at run time and colliding with Autolayout engine. Try giving fixed width or height for these custom views. If it doesn't solve your problem try Following solutions:-

    Solution 1:- Uncomment #use_frameworks inside your pod file.

    Solution 2:- Try deleting derived data. 1. Close Editor window of your Xcode and quit simulator -> 2. Go to Xcode Preferences -> Locations -> 3. Click small grey arrow showing derived data path -> 4. Select your project -> 5. Delete all the folders inside -> 6. Quit Xcode and reopen

    0 讨论(0)
  • 2020-12-02 04:55

    Make sure that you are not directly initialising UIImage or UIFont using assets or fonts added in your project.

    I always create a private func setUp() in my @IBDesignable custom UI classes. which is called from init(frame: CGRect), init?(coder aDecoder: NSCoder). So I finally updated the setup() as the following.

    private func setUp() {
    
         //... Doing initial configurations
    
         // iconImageView.image = UIImage(named: "IconImageName")! // Causing the Crash, use if let OR guard let instead
         if let icon = UIImage(named: "IconImageName") {
              iconImageView.image = icon
              iconImageView.frame.size = icon.size
         }
    
         // nameLabel.font =  UIFont(name: "Calibri-Light", size: 15.0) // Causing the Crash, use if let OR guard let instead
         if let font = UIFont(name: "Calibri-Light", size: size) {
              nameLabel.font =  font
         } else {
              nameLabel.font = UIFont.systemFont(ofSize: size) 
         }
    
         // Doing other stuffs
    }
    
    0 讨论(0)
  • 2020-12-02 04:58

    I had the same issue and I solved it by adding the 'use_frameworks!' to my project's Podfile.

    Hope it helps you.

    0 讨论(0)
  • 2020-12-02 04:59

    I did everything and it did not work till I restarted MAC. Try restarting MAC. Worked for me.

    0 讨论(0)
  • 2020-12-02 05:01

    This is not the case for this question, but maybe I will help someone else.

    I had a similar problem when in my @IBDesignable class I did not implemented both:

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    
        // custom setup
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
    
        // custom setup
    }
    
    0 讨论(0)
提交回复
热议问题