2013-05-15 2 views
0

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 날짜로부터 섹션을 어떻게 만들 것인지, 매우 높이 평가 될 것입니다.

답변

0

제안 사항에 따르면 섹션 수를 얻는 데 걸리는 시간이 늘어나고 각 섹션에는 번호를 입력해야합니다. 각 섹션의 행 수와 같은 이벤트의 수입니다. 당신은

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

에 선언하고,이 후이 도움이 this-

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    headerView=[[UIView alloc] init]; 
    headerView.tag=section+1000; 
    headerView.backgroundColor=[UIColor clearColor]; 


    UILabel *labelInHeader=[[UILabel alloc] init]; 
    labelInHeader.backgroundColor=[UIColor clearColor]; 

    labelInHeader.adjustsFontSizeToFitWidth=YES; 
    labelInHeader.minimumScaleFactor=13.00; 

    labelInHeader.textColor=[UIColor blackColor]; 
    labelInHeader.textAlignment=NSTextAlignmentCenter; 
    labelInHeader.font=[UIFont fontWithName:FONTCENTURYGOTHICBOLD size:20.0]; 

    labelInHeader.frame=CGRectMake(30, 0, 229,47); 
    labelInHeader.lineBreakMode=NSLineBreakByWordWrapping; 
    labelInHeader.numberOfLines=2; 

    [headerView addSubview:labelInHeader]; 
    return headerView; 
} 

희망처럼 각 헤더보기를 넣을 것이다.