samedi 31 janvier 2015

Parse Event Title from Event Kit

So, I would like to read in my array of events from a calendar I am subscribed to. The events all have a similar format, for example with two modules, 'Meaning of Life' and 'Running long distances':


Talk: Meaning of Life


Talk: Running long distances


Talk: Meaning of Life


Talk: Meaning of Life


Talk: Running long distances


I would like to be able to use something like



[[event.title componentsSeparatedByString:@"Talk: "] objectAtIndex:i];


So that in my table view I can have a 'Meaning of life' cell and a 'Running long distances' one. The idea would then be to select one and you could see all the 'Talks' for that module. There are other categories too like 'Workshops' and 'Practicals'.


Currently my code to just display all the events is as follows (ignoring the getting events of selected calendar and producing an array titled arrEvents)



-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableIDCell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TableIDCell"];
}

// Get each single event.
EKEvent *event = [self.arrEvents objectAtIndex:indexPath.row];

// Set its title to the cell's text label.
cell.textLabel.text = event.title;

// Get the event start date as a string value.
NSString *startDateString = [self.appDelegate.eventManager getStringFromDate:event.startDate];

// Get the event end date as a string value.
NSString *endDateString = [self.appDelegate.eventManager getStringFromDate:event.endDate];

// Add the start and end date strings to the detail text label.
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ - %@", startDateString, endDateString];

if (indexPath.row%2 == 0) {
UIColor *altCellColor = [UIColor colorWithWhite:0.7 alpha:0.1];
cell.backgroundColor = altCellColor;
}

return cell;
}


Thanks for taking the time to read :)




Aucun commentaire:

Enregistrer un commentaire