2010-03-26 89 views
0

我有一個視圖,它有一個日期選擇器和一個按鈕添加到它。 還有另一種視圖將上述視圖添加爲子視圖。 但是像touchesBegan和按鈕的動作這樣的事件沒有被點擊在子視圖上。 請幫助嵌套視圖按鈕不是點擊

父視圖的代碼是:

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]; 

和子類的代碼是:

- (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; 
} 

的按鈕不起作用

回答

0

子類的父查看並傳遞給其子女的意見。

+0

嗨。我已經添加了代碼。你能詳細說明我在做什麼錯嗎? – Deepika 2010-03-26 11:53:31

+0

我不知道。但是,如果您想正確執行此操作,請爲其父'UIView'子類,爲'UIButton'和日期選取器對象添加屬性,然後將觸摸傳遞給這些屬性。 – 2010-03-26 11:56:45