Reputation: 17081
There are plenty of questions regarding loading UIViews from Nib files, so that isn't the issue. I have my UIView loading from a Nib file just fine, the trouble is, depending on how I set the view, I either don't have user interaction, or IBActions cause a crash.
Scenario 0:
- (id) init {
self = [super init];
if (self) {
[[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil];
[self addSubview:self.view];
}
return self;
}
Outcome: This loads the view from the Nib, but UIButtons are not tappable. I've also noticed the main view of the View Controller behind this is still interactive, even though this view is supposed to block it.
Scenario 1: Changing this line
[self addSubview:self.view]
to
self = (MyView*)self.view;
Causes the view to block the main view controller view behind it, and a button subview becomes tappable, but... when I connect the button's selector to an IBAction it causes a crash with the error:
-[MyView performSelector:withObject:withObject:]: message sent to deallocated instance 0x12f1cff0
Why is my view being deallocated in this scenario? Before someone asks, I am adding the subview simply like so:
MyView *myView = [[MyView alloc] init];
[self.view addSubview:myView];
Edit: Interestingly, I also notice that awakeFromNib is never being called (in either scenario). Should it be?
Upvotes: 1
Views: 197
Reputation: 50089
the designated initializer is initWithFrame
apart from that :: how is the IBOutlet for view?
Upvotes: 1