는 는 tapkilibrary .like 하이라이트 18aug2011에 14aug2011 사이의 날짜에선택한 여러 날짜를 표시합니다.TapKu 라이브러리에서 여러 날짜를 선택하는 방법은 무엇입니까? 내가 좋아하는 것
2
A
답변
4
-(NSArray*)calendarMonthView:(TKCalendarMonthView *)monthView marksFromDate:(NSDate *)startDate toDate:(NSDate *)lastDate{
NSLog(@"Date Selected is %@",date);
//txtbdate.text=date;
NSDateFormatter *timeFormat = [[[NSDateFormatter alloc] init] autorelease];
NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
[timeFormat setDateFormat:@"yyyy-MM-dd"];
[timeFormat setTimeZone:gmt];
//[timeFormat setLocale:[NSLocale currentLocale]];
//[timeFormat setTimeZone:[NSTimeZone localTimeZone]];
NSString *theTime = [timeFormat stringFromDate:date];
NSLog(@"%@",theTime);
objappdel.strdate=theTime;
[tkmonthView reload];
AppointmentDetail *appointmentDetail=[[AppointmentDetail alloc]initWithNibName:@"AppointmentDetail" bundle:nil];
[self.navigationController pushViewController:appointmentDetail animated:YES];
[appointmentDetail release];
}
- (NSArray*)calendarMonthView:(TKCalendarMonthView *)monthView marksFromDate:(NSDate *)startDate toDate:(NSDate *)lastDate
{
NSMutableArray * data = [[NSMutableArray alloc] init];
NSDateFormatter *dateForm = [[NSDateFormatter alloc] init];
NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
[dateForm setDateFormat:@"yyyy-MM-dd"];
[dateForm setTimeZone:gmt];
NSDate *date ;
for (int i=0; i<[objappdel.arrDate count]; i++)
{
NSString *time;
time=[objappdel.arrDate objectAtIndex:i];
//time= [[[jobData valueForKey:@"Record"] objectAtIndex:i] valueForKey:@"JobStartDate"];
//time = [[time componentsSeparatedByString:@" "] objectAtIndex:0];
date = [dateForm dateFromString:time];
[data addObject:[NSString stringWithFormat:@"%@",date]];
}
NSArray *copy = [data copy];
NSInteger index = [copy count] - 1;
for (id object in [copy reverseObjectEnumerator])
{
if ([data indexOfObject:object inRange:NSMakeRange(0, index)] != NSNotFound)
{
[data removeObjectAtIndex:index];
}
index--;
}
NSLog(@"sorted dates are %@",copy);
// Initialise empty marks array, this will be populated with TRUE/FALSE in order for each day a marker should be placed on.
NSMutableArray *marks = [NSMutableArray array];
// Initialise calendar to current type and set the timezone to never have daylight saving
NSCalendar *cal = [NSCalendar currentCalendar];
[cal setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
// Construct DateComponents based on startDate so the iterating date can be created.
// Its massively important to do this assigning via the NSCalendar and NSDateComponents because of daylight saving has been removed
// with the timezone that was set above. If you just used "startDate" directly (ie, NSDate *date = startDate;) as the first
// iterating date then times would go up and down based on daylight savings.
NSDateComponents *comp = [cal components:(NSYearCalendarUnit | NSMonthCalendarUnit |
NSDayCalendarUnit | NSWeekdayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit)
fromDate:startDate];
NSDate *d = [cal dateFromComponents:comp];
// Init offset components to increment days in the loop by one each time
NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
[offsetComponents setDay:1];
// for each date between start date and end date check if they exist in the data array
while (YES) {
// Is the date beyond the last date? If so, exit the loop.
// NSOrderedDescending = the left value is greater than the right
if ([d compare:lastDate] == NSOrderedDescending)
{
break;
}
// If the date is in the data array, add it to the marks array, else don't
//NSLog(@"%@",[d description]);
if ([data containsObject:[d description]]) {
[marks addObject:[NSNumber numberWithBool:YES]];
} else {
[marks addObject:[NSNumber numberWithBool:NO]];
}
// Increment day using offset components (ie, 1 day in this instance)
d = [cal dateByAddingComponents:offsetComponents toDate:d options:0];
}
[offsetComponents release];
return [NSArray arrayWithArray:marks];
}
이 위임 메서드를 사용하십시오. 강조 표시하려는 날짜의 NSArray를 반환합니다.
1
먼저 배열에 날짜를 입력하면됩니다. 이것에 대한 코드입니다. 이 후
- (void)calendarMonthView:(TKCalendarMonthView *)monthView didSelectDate:(NSDate *)d {
NSLog(@"selected Date IS - %@",inDate);
[myArray addObject:d];
for (id entry in myArray)
{
if (inDate == nil && outDate == nil)
{
inDate = d;
outDate = d;
}
if ([d compare:inDate] == NSOrderedAscending)
{
inDate = d;
}
if ([d compare:outDate] == NSOrderedDescending)
{
outDate = d;
}
d = nil;
}
}
당신은이 두 날짜 사이의 선택 날짜를 만들 수있는 버튼 클릭 액션을 사용합니다. 그것을위한 코드는 다음과 같습니다
이- (IBAction)goBtn:(id)sender
{
NSLog(@"startDate is: %@",inDate);
NSLog(@"endDate is: %@",outDate);
[calendar reload];
inDate = nil;
outDate = nil;
}
}
그런 다음 하나의 대리자 메서드에 그냥이 두 날짜 사이의 모든 날짜를 포함하는 배열을해야한다. 버튼 클릭 직후에 호출됩니다. 그것을위한 코드는 다음과 같습니다
- (NSArray*)calendarMonthView:(TKCalendarMonthView *)monthView marksFromDate:(NSDate *)startDate toDate:(NSDate *)lastDate {
//***********
NSMutableArray *tempData = [[NSMutableArray alloc] init];
NSDate *nextDate;
for (nextDate = inDate ; [nextDate compare:outDate] < 0 ; nextDate = [nextDate addTimeInterval:24*60*60]) {
// use date
NSLog(@"%@",nextDate);
[tempData addObject:[NSString stringWithFormat:@"%@",nextDate]];
}
[tempData addObject:[NSString stringWithFormat:@"%@",outDate]];
//***********
NSMutableArray *marks = [NSMutableArray array];
NSCalendar *cal = [NSCalendar currentCalendar];
[cal setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
NSDateComponents *comp = [cal components:(NSMonthCalendarUnit | NSMinuteCalendarUnit | NSYearCalendarUnit |
NSDayCalendarUnit | NSWeekdayCalendarUnit | NSHourCalendarUnit | NSSecondCalendarUnit)
fromDate:startDate];
NSDate *d = [cal dateFromComponents:comp];
NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
[offsetComponents setDay:1];
while (YES) {
if ([d compare:lastDate] == NSOrderedDescending) {
break;
}
if ([tempData containsObject:[d description]]) {
[marks addObject:[NSNumber numberWithBool:YES]];
} else {
[marks addObject:[NSNumber numberWithBool:NO]];
}
d = [cal dateByAddingComponents:offsetComponents toDate:d options:0];
}
return [NSArray arrayWithArray:marks];
}
나는 희망이 당신을 도왔다. 문제가 발생하면 알려주십시오.
관련 문제
- 1. 편집 (패치) 내가 좋아하는 것
- 2. 는 내가 좋아하는 것 2005
- 3. 레일 - 테이블에서 마지막 날짜를 선택하는 방법은 무엇입니까?
- 4. 여러 확인란을 선택하는 방법은 무엇입니까?
- 5. tapku 라이브러리에서 단색 배경의 마킹 날짜를 세 가지 색상으로 지정하려는 경우 목표 C
- 6. 내가 좋아하는 색상 코드를 찾는 방법은 무엇입니까?
- 7. Box2D의이 - 상자와 거리 관절,이 같은 뭔가 내가 좋아하는 것
- 8. CBitmap과 CImage는 서로 바꿔 쓸 수 있습니까? 내가 좋아하는 것
- 9. iPhone 주소록 : 여러 연락처를 선택하는 방법은 무엇입니까?
- 10. 여러 파티션에서 SQL을 선택하는 방법은 무엇입니까?
- 11. 조건부 유효성을 테스트 할 수있는 방법은 무엇입니까? 레일 3.0.9 및 RSpec에 내가 좋아하는 것 2.
- 12. MITM을 가장 좋아하는 방법은 무엇입니까?
- 13. 내가 좋아하는 모델이
- 14. 내가 좋아하는 정규 표현식을
- 15. 내가 좋아하는 도메인 클래스가
- 16. SQL 쿼리에서 날짜를 선택하는 방법
- 17. 내가 좋아하는 뭔가가 있다면 '의이
- 18. 자바 스크립트 테스트 (문자열 형식) 날짜는 30 일 전 내가 좋아하는 캐릭터 라인 형식으로 날짜를
- 19. Tapku 캘린더 이벤트
- 20. Scrollable Grid (야후 이메일을 좋아하는 것)
- 21. 날짜를 빼는 방법은 무엇입니까?
- 22. 사용자가 자신의 라이브러리에서 음악을 선택하는 방법
- 23. 내 라이브러리에서 여러 i/p 파일 지원을 처리하는 방법은 무엇입니까?
- 24. PHP, SimpleXML, <tag>에 액세스하는 방법은 id 속성과 이제 배열 위치입니까? 내가 좋아하는 것
- 25. 요소를 선택하는 방법은 무엇입니까?
- 26. TTURLRequestCachePolicy를 선택하는 방법은 무엇입니까?
- 27. schroot : 그것은 내가 좋아하는 뭔가하고 싶은
- 28. 내가 좋아하는 세션 빈에서 여러 가지 방법으로 시도
- 29. PHP 조건문 -> 내가 좋아하는 뭔가가있는 경우 여러 의사 결정
- 30. JQuery를 사용하여 라디오 버튼을 선택하는 방법은 무엇입니까?
당신의 오히려 간단하고 간단한 대답이 모두 약 10 표를 얻는 방법에 흥미가 있습니다. – Till
@Dhara 코드에서 AppointmenDetail 및 tkMonthView는 무엇입니까? 또한, 코드에서 배열을 반환하지 않습니다. 나는 그것이 효과가 없다고 확신한다! 나머지 코드는 http://developinginthedark.com/posts/iphone-tapku-calendar-markers#the-code 데모 코드에서 가져 왔습니다. 너 아니니? 나는 더 많은 것을하려고 노력하고있다. 가능하다면 이것을 할 수 있을까요? http://stackoverflow.com/questions/9686684/ios-tapku-calendar-library-allow-selecting-multiple-dates-for-current-month 감사합니다. – applefreak
@AppleDeveloper tkMonthView는 TkMonthView 클래스의 객체입니다. AppointmenDetail이 내 로컬 클래스입니다. gitHub에서 코드를 얻었습니다. – Dhara