I am trying to load a a view from the nib and add it to the main view. Here is my code.
I loaded the nib in the initWithFrame
of the @interface AddTaskView:UIView
:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
NSLog(@"init with frame");
// Initialization code
NSArray *addTaskArrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"AddTaskView"
owner:self
options:nil];
self=[addTaskArrayOfViews objectAtIndex:0];
}
return self;
}
After that I init the view and add it to the main view:
self.addTaskView=[[AddTaskView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)];
[self.view addSubview:self.addTaskView];
Everything works fine but the AddTaskView doesn't receive the touch event. I have three buttons and when I try to push them they don't receive the actions. I made the nib of type "AddTaskView" but without any luck. I also looked in the subviews and the "AddTaskView" is the top view.
I added this code in the AddTaskView to see if I get a touch and no response:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"touch");
}
How do I get a chance to respond to touch events?
I think you have to register a touch dispatcher and then try to get touch....following is the code for that