Cub71
Cub71

Reputation: 323

Unable to get calendars title

I am presenting a tableview where users can select in which calendar to put an event. In iOS 5 I use the new EKCalendarChooser but in order to accomodate those who don't update I am making my own calendarchooser.

To get the calendars on the phone I use this:

- (void)viewDidLoad 
{    
    [super viewDidLoad];        
    [self setWritableCalendars:[self getAllWritableCalendars]];
}


- (NSArray *)getAllWritableCalendars
{
    EKEventStore *eventDB = [[EKEventStore alloc]init];    
    NSMutableArray *allCalendars = [NSMutableArray arrayWithArray:[eventDB calendars]];
    NSPredicate *filter = [NSPredicate predicateWithFormat:@"allowsContentModifications == YES"];
    [allCalendars filterUsingPredicate:filter];

    NSArray *_writables = [NSArray arrayWithArray:allCalendars];

    return _writables;
}




- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    if ([[self writableCalendars] count] > 0)
    {
        cell.textLabel.text = [[[self writableCalendars] objectAtIndex:[indexPath row]] title];
    }
    else 
    {
        cell.textLabel.text = @"No calendars found";
    }
    return cell;
}

The problem is that the even though the writableCalendars has two objects, the [[[self writableCalendars] objectAtIndex:[indexPath row]] title] is nil ever time. The tableview is presented with two cells that is clickable but with no text.

When I force this code to run in iOS 5, it works fine and all calendar titles are presented.

What am I missing here?

Upvotes: 1

Views: 241

Answers (2)

NSCry
NSCry

Reputation: 1652

From that code I wrote down following code

EKEventStore *eventDB = [[EKEventStore alloc]init];    
NSMutableArray *allCalendars = [NSMutableArray arrayWithArray:[eventDB calendars]];
for (int i=0; i<allCalendars.count; i++)
{
    NSLog(@"Title:%@",[[allCalendars objectAtIndex:i] title]);
}

Output:
2012-02-03 17:47:31.099 FunDoc[4100:11f03] Title:Calendar
2012-02-03 17:47:31.100 FunDoc[4100:11f03] Title:Birthdays

Upvotes: 0

ott--
ott--

Reputation: 5722

Your array has two objects, but are the object's title really set? Maybe include a NSLog (@"%@", [[self.writableCalendars objectAtIndex:indexPath.row] description]);

In your viewDidLoad method, [super viewDidLoad]; should be the first line.

Upvotes: 1

Related Questions