IBOutlet is nil inside custom UIView (Using STORYBOARD)

前端 未结 7 1585
忘掉有多难
忘掉有多难 2020-12-25 13:22

I have a custom UIView class. Inside it I have declared an IBOutlet property for UIImageView.

#import 

        
7条回答
  •  情深已故
    2020-12-25 14:02

    I just had the exact same problem and the solution is really easy:

    You're accessing myImage to soon - that's it.

    Withing -(id) initWithCoder:(NSCoder *)aDecoder{ and - (id)initWithFrame:(CGRect)frame the UIView is not already drawed. So myImage is not initalized yet.

    You can test it if you add a UIButton and an IBAction and do something like this:

    - (IBAction)buttonClicked:(id)sender {
        NSLog(@"%@",myImage);
    }
    

    And you'll see how myImage is not nil anymore.

提交回复
热议问题