开发者

Nested Views-button is not clicking

开发者 https://www.devze.com 2022-12-24 14:08 出处:网络
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.

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 beco开发者_开发知识库meFirstResponder];
        [btn addTarget:self action:@selector(SelectedVal:) forControlEvents:UIControlEventTouchDown];
        [self addSubview:btn];


    }
    return self;
}

The button is not working


Subclass the parent view and pass touches to its children views.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号