2015-01-23 2 views
1

페이징으로 UIScrollview를 만들었지 만 일부 페이지에 날짜 선택 도구를 추가하려고합니다. 그러나 날짜 선택 도구 스크롤이 작동하지 않습니다.수평 페이징 스크롤보기에 날짜 선택 도구를 추가하는 방법은 무엇입니까?

NSArray *colors = [NSArray arrayWithObjects:[UIColor redColor], [UIColor greenColor], [UIColor blueColor], nil]; 
for (int i = 0; i < colors.count; i++) { 
    CGRect frame; 
    frame.origin.x = self.scrollView.frame.size.width * i; 
    frame.origin.y = 0; 
    frame.size = self.scrollView.frame.size; 

    UIView *subview = [[UIView alloc] initWithFrame:frame]; 
    subview.backgroundColor = [colors objectAtIndex:i]; 
    CGRect pickerFrame = CGRectMake(0,100,100,100); 

    UIDatePicker *myPicker = [[UIDatePicker alloc] initWithFrame:pickerFrame]; 
    [myPicker addTarget:self action:@selector(pickerChanged:) forControlEvents:UIControlEventValueChanged]; 
    [self.view addSubview:myPicker]; 
    [myPicker release]; 
    [self.scrollView addSubview:subview]; 
    [subview release]; 
} 

self.scrollView.contentSize = CGSizeMake(self.scrollView.frame.size.width * colors.count, self.scrollView.frame.size.height); 

self.pageControl.currentPage = 0; 
self.pageControl.numberOfPages = colors.count; 
+0

날짜 선택기 스크롤이 작동하지 않습니다. –

답변

1

대신 self.view에 피커보기를 추가, self.scrollView

[self.scrollView addSubview:myPicker]; 

또는 사용자가 텍스트 필드에 입력보기로 선택기보기를 추가 할 수 있습니다에 추가

for (int i = 0; i < colors.count; i++) { 
    CGRect frame; 
    frame.origin.x = self.scrollView.frame.size.width * i; 
    frame.origin.y = 0; 
    frame.size = self.scrollView.frame.size; 

    UIView *subview = [[UIView alloc] initWithFrame:frame]; 
    subview.backgroundColor = [colors objectAtIndex:i]; 
    //CGRect pickerFrame = CGRectMake(0,100,100,100); 

    myTextField = [[UITextField alloc]initWithFrame: 
           CGRectMake(10, 100, 300, 30)]; //if you dont want to show the text field you can change the frame to CGRectMake(0, 0, 1, 1) 
    myTextField.borderStyle = UITextBorderStyleRoundedRect; 
    myTextField.textAlignment = NSTextAlignmentCenter; 
    myTextField.delegate = self; 
    [self.view addSubview:myTextField]; 

    UIDatePicker *myPicker = [[UIDatePicker alloc] initWithFrame:pickerFrame]; 
    [myPicker addTarget:self action:@selector(pickerChanged:) forControlEvents:UIControlEventValueChanged]; 
    [myTextField setInputView:myPicker]; 
    [self.scrollView addSubview:myTextField]; 


    [myPicker release]; 

    [self.scrollView addSubview:subview]; 
    [subview release]; 
} 

피커를 표시하려면 아래 방법을 호출하십시오. [self showPickerView]

- (void)showPickerView 
{ 
    [myTextField becomeFirstResponder]; 
} 
+0

답장을 보내 주셔서 감사합니다. 이제는 잘 작동합니다. –

관련 문제