Hello everyone,
I've spent all evening trying to get to grips with something that I'm sure must be fairly simple. I'm trying to devise a framework that will allow me, within a View Based Application to have a superview XIB, with a UIView (containerView) inside. I then wish to be able to populate containerView with various XIBs, each with its own viewcontroller. I hope this will allow me to build and expand my app to contain many uniquely designed and controlled views. I really hope that i've made a silly rookie mistake in how i've set this up, as whilst I can get the XIB files to load (at the moment triggered by buttons in the superview), I can't get them to respond to touch events.
This is how the XIB is loaded in the IBAction attached to its button:
Code:
UIView *nv = [[[NSBundle mainBundle] loadNibNamed:@"view2" owner:self options:nil] objectAtIndex:0];
[containerView addSubview:nv];
That XIB file has a UIViewController object, with its Class set to "view2". When the XIB is displayed with the button press, I have used NSLog to confirm that -ViewDidLoad is running.
Inside view2.m I have implemented
Code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touching in view 2");
}
but the application ignores this, and passes the event up the chain to the superview.
I have also added a UIButton to the XIB, and hooked it into an IBOutlet and IBAction in view2.m. If I change the property of the button in ViewDidLoad, for instance changing its background colour, then it works fine. However, the when the IBAction is called it kills the app.
Am I barking totally up the wrong tree here? Any clues as to what i've messed up? My instinct is that i've misunderstood some element of the UIView/view controller relationship, and I'd be very grateful for any insight as to where my logic falls over.
I will say one other thing that appears odd, in view2.xib, File Owner's 'view' outlet is not set - this feels wrong, but if I set it to the View then nothing appears when I click on the button in the superview.
Any help really appreciated, and thank you for putting up with my dyslexic ramblings.
Many Thanks,
Dan