2011-08-27 7 views
0

베어는 아이폰 프로그래밍 멍청한 놈은UIDatePicker는 기본적으로 Null을 반환합니까? 여기에 나와 함께

가 UIDatePicker에 대한 나의 구현은 기본적으로 여기에 하나

입니다 ...이 문제를 알아 내려고 :

UIDatePicker pop up after UIButton is pressed

내 문제가있는 UIDatePicker이 튀어 나올 경우 그 그리고 사용자가 날짜를 변경하지 않고 그냥 완료되면, exc_bad_access가 완료되면 1 분 이상 시간을 이동하지 않고 충돌하므로 null을 반환하는 것으로 보입니다.

나는 UIDatePicker에 대한 NSDate를 가져 와서 계산을 수행하는 방법으로 전달하지만 완료되면 그냥 충돌합니다.

UIDatePicker의 기본값을 설정하는 방법이 있습니까? 아니면 그냥 팝업 값이 있습니까? (일반적으로 현재 시간이지만 null을 반환합니다). 나는 기본값을 자정으로 설정하거나 단순히 그것이 팝업으로 나타나는 현재 시간을 설정하는 방법을 찾고 있었다.

여기 내 시도가 자정으로 설정에서의 (작동하지 않았다, 추락) :

- (void)changeDate:(UIDatePicker *)sender { 
NSLog(@"New Date: %@", sender.date); 
} 

- (void)removeViews:(id)object { 
[[self.view viewWithTag:9] removeFromSuperview]; 
[[self.view viewWithTag:10] removeFromSuperview]; 
[[self.view viewWithTag:11] removeFromSuperview]; 
} 

- (void)dismissDatePicker:(id)sender { 
CGRect toolbarTargetFrame = CGRectMake(0, self.view.bounds.size.height, 320, 44); 
CGRect datePickerTargetFrame = CGRectMake(0, self.view.bounds.size.height+44, 320, 216); 
[UIView beginAnimations:@"MoveOut" context:nil]; 
[self.view viewWithTag:9].alpha = 0; 
[self.view viewWithTag:10].frame = datePickerTargetFrame; 
[self.view viewWithTag:11].frame = toolbarTargetFrame; 
[UIView setAnimationDelegate:self]; 
[UIView setAnimationDidStopSelector:@selector(removeViews:)]; 
[UIView commitAnimations]; 
} 

- (IBAction)callDP:(id)sender { 
if ([self.view viewWithTag:9]) { 
    return; 
} 
CGRect toolbarTargetFrame = CGRectMake(0, self.view.bounds.size.height-216-44, 320, 44); 
CGRect datePickerTargetFrame = CGRectMake(0, self.view.bounds.size.height-216, 320, 216); 

UIView *darkView = [[[UIView alloc] initWithFrame:self.view.bounds] autorelease]; 
darkView.alpha = 0; 
darkView.backgroundColor = [UIColor blackColor]; 
darkView.tag = 9; 
UITapGestureRecognizer *tapGesture = [[[UITapGestureRecognizer alloc]  initWithTarget:self   action:@selector(dismissDatePicker:)] autorelease]; 
[darkView addGestureRecognizer:tapGesture]; 
[self.view addSubview:darkView]; 

UIDatePicker *datePicker = [[[UIDatePicker alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height+44, 320, 216)] autorelease]; 
datePicker.tag = 10; 
[datePicker addTarget:self action:@selector(changeDate:)  forControlEvents:UIControlEventValueChanged]; 
[self.view addSubview:datePicker]; 

UIToolbar *toolBar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height, 320, 44)] autorelease]; 
toolBar.tag = 11; 
toolBar.barStyle = UIBarStyleBlackTranslucent; 
UIBarButtonItem *spacer = [[[UIBarButtonItem alloc]  initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease]; 
UIBarButtonItem *doneButton = [[[UIBarButtonItem alloc]  initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissDatePicker:)] autorelease]; 
[toolBar setItems:[NSArray arrayWithObjects:spacer, doneButton, nil]]; 
[self.view addSubview:toolBar]; 

[UIView beginAnimations:@"MoveIn" context:nil]; 
toolBar.frame = toolbarTargetFrame; 
datePicker.frame = datePickerTargetFrame; 
darkView.alpha = 0.5; 
[UIView commitAnimations]; 
} 
: 당신이 싶어 링크를 겪고 귀찮게하지 않는 경우 여기
NSString *[email protected]"2011-08-27 00:00:00 +0000"; 
NSDateFormatter *df = [[NSDateFormatter alloc] init]; 
[df setDateFormat:@"yyyy-MM-dd hh:mm:ss a"]; 
NSDate *myDate = [df dateFromString: myDateAsAStringValue]; 
[datePicker setDate:myDate]; 
[self changeDate:datePicker]; 

이 fluchpunkt의 코드입니다

감사합니다.

답변

0

그냥 github에서이 코드를 다운로드하십시오. 그것은 내부에 데모 프로젝트가 필요한 것입니다.

here

관련 문제