JSON을 사용하여 공유 Google 캘린더의 일정을 내 앱으로 가져옵니다. 일부 날짜에는 2 개 이상의 이벤트가 있습니다. here에서 볼 수 있듯이 {gd $ when}의 {startDate} 날짜는 긴 형식 (2013-04-28T19 : 00 : 00 + 00 : 00)으로 표시됩니다 .각 섹션은 날짜 형식은 dd-MM-yy입니다. 그런 다음 cell.textLabel.Text는 Title/$ t이고 cell.detailTextLabel.Text는 gd $/startTime의 시간 (hh : mm)이됩니다. 오늘 날짜와 같거나 이후 인 것을 보여주고 싶을뿐입니다.UITableview가 고유 날짜별로 섹션으로 정렬되었습니다.
raywenderlich.com의 튜토리얼과 일치시키기 위해 제가 놀았습니다. 지금 내 코드는 다음과 같지만 아직 구현하지 않았습니다. tableviewcontroller에
#define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
#define googleURL [NSURL URLWithString: @"http://www.google.com/calendar/feeds/kao1d80fd2u5kh7268caop11o4%40group.calendar.google.com/public/full?alt=json"]
#import "ViewController.h"
@interface ViewController() {
IBOutlet UILabel* humanReadble;
IBOutlet UILabel* jsonSummary;
}
@end
@implementation ViewController
-(void)viewDidLoad
{
[super viewDidLoad];
dispatch_async(kBgQueue, ^{
NSData* data = [NSData dataWithContentsOfURL:googleURL];
[self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES];
});
}
- (void)fetchedData:(NSData *)responseData {
//parse out the JSON data
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
NSArray* feed = [json valueForKeyPath:@"feed.entry"];
NSLog(@"feed: %@", feed);
for (int i=0; i<[feed count]; i++) {
NSDictionary* event = [feed objectAtIndex:i];
NSString* eventTitle = [event valueForKeyPath:@"title.$t"];
NSLog(@"Title: %@", eventTitle);
}
}
@end
누군가가 포인터를 줄 수 있다면 - 특히 t o 날짜로부터 섹션을 어떻게 만들 것인지, 매우 높이 평가 될 것입니다.