여러보기가있는 프로그램을 작성 중입니다. 뷰 사이에 날짜 변수를 전달하고 싶습니다. extern NSDate *chooseDate
을 사용하여 전역 변수를 만들었습니다. 뷰 중 하나에 변수 NSDate *date
을 선언합니다. 그런 다음 date = chooseDate
을 설정합니다. 다음 날짜를 추가하려면 다음 코드를 사용하십시오.NSdate 관련 문제
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setDay:(int)daycount];
date = [calendar dateByAddingComponents:components toDate:date options:0];
문제는 chooseDate
가 NSDate
로 인식되지 않는 것 같다. 코드가 date = [calendar ...]
에서 중단됩니다. 나는 이것이 왜 일어나고 있는지에 관해서 분실하고있다. 내가 분명히 설명하기를 바란다. 어떤 아이디어?
속성 (?)의 '날짜'코드를 표시 할 수 있습니까? – FreeAsInBeer
날짜 = 선택 날짜; \t \t NSDateComponents * 구성 요소 = [[NSDateComponents alloc] init]; [구성 요소 setDay : (int) daycount]; date = [calendar dateByAddingComponents : 구성 요소 toDate : 날짜 옵션 : 0]; \t dateComponents = [calendar components : unitFlags fromDate : date]; 년 = [dateComponents year]; month = [dateComponents month]; day = [날짜 구성 요일]; 시간 = [날짜 구성 시간]; min = [dateComponents 분]; \t NSDateFormatter * formatter = [[[NSDateFormatter alloc] init] autorelease]; [formatter setDateStyle : NSDateFormatterLongStyle]; [showDate setText : [formatter stringFromDate : date]]; – tombuarts
형식에 대해 죄송합니다. 객관적인 코드의 코드처럼 보이게 만드는 방법을 기억하지 못합니다. – tombuarts