0

I am getting events from a Shared Google Calendar into my App using JSON. On some dates there are 2 or more events. As you can see here - the dates (found under {gd$when}, {startDate} are in a long format (2013-04-28T19:00:00.000+02:00). I would need each section to be a date in the format dd-MM-yy. Then the cell.textLabel.Text would be the Title/$t, and the cell.detailTextLabel.Text would be the time (hh:mm) from gd$when/startTime. I would only want to show those that are equal to or after todays date.

I have played around with it, to match a tutorial on raywenderlich.com. My code right now looks like this, but I haven't yet implemented it into a 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

If anybody can give a pointer - especially as to how I would create the sections from the date, it would be highly appreciated

catu
  • 888
  • 6
  • 24

1 Answers1

0

Where as my suggestion says to you create the number of section as you get number of dates you get, and in each section you have to put number of events that would be the number of rows at each section. which you will declare at

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

and after this put the view for each header like 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;
}

Hope this helps.

iEinstein
  • 2,100
  • 1
  • 21
  • 32