2013-03-10 2 views

답변

4

설정합니다 IBAction를로 DatePicker에서의 value_changed 이벤트 :

예 :

- (IBAction) dateChanged:(id)sender { 
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle]; 
    self.currentTextField.text = [dateFormatter stringFromDate:[self.datePicker date]]; 
} 
+0

안녕하세요, 나는 Daubry를 잘 알고 있습니다. –

+0

형식을 하드 코딩하는 대신 날짜 형식화 프로그램의 스타일을 NSDateFormatterMediumStyle과 같은 것으로 설정하는 것이 좋습니다. – rmaddy

+0

@rmaddy : 귀하의 의견에 따라, 바로, 내 대답을 편집 – vdaubry

1

UIDatePickerdate 속성을 가지고 있습니다. 이 속성을 통해 NSDate에 액세스 할 수 있습니다.

그런 다음 당신은 아마 당신의 NSDate에서 NSString를 만들 NSDateFormatter를 사용하고 UITextField에 표시 할 수 있어야합니다. 가장 간단한 방법으로

, 코드는 다음과 같이한다 :

myTextField.text = [myDateFormatter stringFromDate:myDatePicker.date]; 
+0

에 선택기를 추가 할 수 있습니다 선택. – rmaddy

2

당신이 할 수있는 연결 관리자에서 동작을 Value Changed 이벤트로 설정하여 UIDatePicker에서 변경된 날짜를 업데이트하는 방법을 가지고 작업을 구현하십시오. 등 사용자가을 할 때 알림을받을하는 데 사용할 수있는 이벤트가 있다는 것을 추가 값이

- (IBAction)datePickerValueChanged:(id) sender{ 

    NSDateFormatter *df = [[NSDateFormatter alloc] init]; 
    df.dateStyle = NSDateFormatterMediumStyle; 

    self.textfield.text = [NSString stringWithFormat:@"%@",[df stringFromDate:datePicker.date]]; 

} 

같은 것을 텍스트 필드 또는 당신은 UIDatePicker

[datePicker addTarget:self action:@selector(updateMyDate:) forControlEvents:UIControlEventEditingChanged]; 
0
NSDateFormatter *df = [[NSDateFormatter alloc] init]; 
    df.dateFormat = "dd-MMMM-yyyy hh:mm a" 

    //To show date in textfield  

    myTextField.text = [df stringFromDate:datePicker.date]; 

    //To show selected date on datepicker from textfield 

    datePicker.date = df.dateFromString(myTextField.text) 
관련 문제