我正在展示一个表格视图,用户可以在其中选择放置事件的日历。在iOS 5中,我使用了新的EKCalendarChooser,但是为了适应那些不进行更新的人,我正在制作自己的calendarchooser。

要在手机上获取日历,请使用以下方法:

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


问题在于,即使writableCalendars有两个对象,[[[self writableCalendars] objectAtIndex:[indexPath row]] title]始终是零。表格视图具有两个可单击但没有文本的单元格。

当我强制此代码在iOS 5中运行时,它可以正常工作,并显示所有日历标题。

我在这里想念什么?

最佳答案

从该代码中,我写下了以下代码

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]);
}


输出:
2012-02-03 17:47:31.099 FunDoc [4100:11f03]标题:日历
2012-02-03 17:47:31.100 FunDoc [4100:11f03]标题:生日

10-06 05:12
查看更多