2013-05-15 3 views
0

Я получаю события из Google Календаря Google в мое приложение с помощью JSON. В некоторые даты есть 2 или более события. Как вы можете видеть here - даты (найдены в {gd $ when}, {startDate} в длинном формате (2013-04-28T19: 00: 00.000 + 02: 00). Мне понадобится, чтобы каждый раздел был date в формате dd-MM-yy. Тогда cell.textLabel.Text будет Title/$ t, а cell.detailTextLabel.Text будет временем (hh: mm) из gd $, когда/startTime. только хочу показать те, которые равны или после сегодняшней даты.UITableview отсортировано по разделам по дате

Я играл с ним, чтобы соответствовать учебнику на raywenderlich.com. Мой код сейчас выглядит так, но я еще не реализовал его в таблицу viewcontroller

#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; 
} 

Надеется, что это помогает.

Смежные вопросы