2011-12-13 1 views
1

그래서 날짜 선택 도구에서 날짜를 가져 오는 방법을 잘 알고 있습니다. 하지만 UIActionSheet의 날짜 선택 도구에서 가져올 수없는 것 같습니다. 현재 설정은 데이터 소스에 대해 동일한보기를 사용하는 데이터 소스에 대해 didSelectRow 메소드를 사용하는 몇 가지 선택기로 데이터를 입력하는 형식입니다.UIDatePicker, UIActionSheet 및 데이터 처리

동일한 방식으로 UIDatePicker에서 작동하지 않는 것 같습니다. 여기 내 데이트 피커를 위해 지금까지 가지고있는 것은, 다른 값을 변경하는 것을 처리하는 방법을 포함하여 다른 피커와 비슷합니다.

-(IBAction)ageBox{ 
    pickerAction=[[UIActionSheet alloc]initWithTitle:nil delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; 
    [pickerAction setActionSheetStyle:UIActionSheetStyleBlackTranslucent]; 
    CGRect pickerFrame = CGRectMake(0, 40, 0, 0); 

    UIDatePicker *datePicker =[[UIDatePicker alloc]initWithFrame:pickerFrame]; 

    [pickerAction addSubview:datePicker]; 

    UISegmentedControl *closeButton=[[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObject:@"OK"] ]; 
    closeButton.momentary = YES; 
    closeButton.frame=CGRectMake(260, 7.0f, 50.0f, 30.0f); 
    closeButton.segmentedControlStyle =UISegmentedControlStyleBar; 
    closeButton.tintColor = [UIColor blackColor]; 
    date = datePicker.date; 
    [closeButton addTarget:self action:@selector(closePicker) forControlEvents:UIControlEventValueChanged]; 
    [pickerAction addSubview:closeButton]; 
    whatToChange = 5; 
    [pickerAction showInView:self.view]; 
    [pickerAction setBounds:CGRectMake(0, 0, 320, 464)]; 
} 

가 파괴되기 전에 내가 그것에서 잡아 당겨, ​​확인을 클릭 할 때 액션 시트, 또는 동안 날짜 선택에서 날짜를 잡아 당겨 어떤 도움?

답변

1

나는 방법의 첫 번째 코드 줄을 기준으로 pickerActionivarself이라는 가정을하고 있습니다. 나는 두 가지 방법을 생각해 볼 수 있습니다.

1) 도 ivar으로 설정하십시오. 그렇게하면 'ok' 방법에 대한 참조가 있습니다.

2) pickerAction에서 참조 번호를 얻으십시오. 당신이 subview으로 datePicker을 추가 한 때문에, 당신은과 같이 찾을 수 있습니다 :

// Somewhere in your "ok" method 
    for (UIView *view in pickerAction.subviews) { 
     if ([view isKindOfClass:[UIDatePicker class]]){ 
      UIDatePicker *picker = (UIDatePicker *)view; 
      NSDate *pickedDate = picker.date; 
     } 
    } 
+0

두 번째는 마법처럼 일했다. 나는 NSDateFormatter를 추가했다. * df = [[NSDateFormatter alloc] init]; df.dateStyle = NSDateFormatterMediumStyle; date = [NSString stringWithFormat : @ "% @", [df stringFromDate : pickedDate]]; 그것을 다른 곳에서 설정할 수있는 문자열로 만들 수 있습니다. 감사! –