Nested Views-button aint clicking

Posted by Deepika on Stack Overflow See other posts from Stack Overflow or by Deepika
Published on 2010-03-26T11:45:28Z Indexed on 2010/05/29 17:02 UTC
Read the original article Hit count: 221

Filed under:
|
|

i have a view which has a datepicker and a button added to it. There is another view which adds the above view as subview. But the events like touchesBegan and button's action are not being clicked on the subview. Please help

The code of the parent view is:

iTagDatePicker *dt=[[iTagDatePicker alloc] initWithFrame:CGRectMake(0.0, 180.0, 320.0, 240.0)];
    //dt.userInteractionEnabled=YES;
    //[dt becomeFirstResponder];

    dt.backgroundColor=[UIColor clearColor];
    [UIView beginAnimations:@"animation" context:nil];
    [UIView setAnimationDuration:1.0];
    CGPoint cntr;
    cntr.x=160.0;
    cntr.y=420.0;
    dt.center=cntr;
    [self.view addSubview:dt];
    self.view.userInteractionEnabled=YES;
    CGPoint cntr1;
    cntr1.x=160.0;
    cntr1.y=158.0;
    dt.center=cntr1;
    [UIView commitAnimations];
    [dt release];

and the code for the sub class is:

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        dtPicker=[[UIDatePicker alloc] initWithFrame:CGRectMake(frame.origin.x, frame.origin.y, 320.0, 216.0)];
        dtPicker.datePickerMode=UIDatePickerModeDate;
        dtPicker.date=[NSDate date];
        [self addSubview:dtPicker];

        btn=[[UIButton buttonWithType:UIButtonTypeDetailDisclosure]retain];
        btn.frame=CGRectMake(110.0, 400.0, 100.0, 20.0);
        [btn setTitle:@"Done" forState:UIControlStateNormal];
        btn.userInteractionEnabled=YES;
        [btn becomeFirstResponder];
        [btn addTarget:self action:@selector(SelectedVal:) forControlEvents:UIControlEventTouchDown];
        [self addSubview:btn];


    }
    return self;
}

The button is not working

© Stack Overflow or respective owner

Related posts about iphone

Related posts about view