2011-10-15 51 views
1

我正在提供一个tableview,用户可以选择在哪个日历中放置一个事件。在iOS 5中,我使用新的EKCalendarChooser,但为了容纳那些不更新的人,我正在制作自己的日历存储器。无法获取日历标题

为了让我用这个手机上的日历:

- (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有两个目的,[[[自我writableCalendars] objectAtIndex:[indexPath行]标题]没有时间。该tableview呈现两个可点击但没有文本的单元格。

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

我在这里错过了什么?

回答

0

从那个代码我写下以下代码

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]标题:生日

1

你的数组有两个对象,但对象的标题真的设置了吗?也许包括一个NSLog (@"%@", [[self.writableCalendars objectAtIndex:indexPath.row] description]);

在你的viewDidLoad方法中,[super viewDidLoad];应该是第一行。

+0

我试过了,标题都是零,在对象和'将允许修改'都没有。真奇怪。 – Cub71

+0

你可以在建立对象的地方显示代码吗? –

+0

writableCalendars是一个正常合成的数组属性。它建立在 - (NSArray *)getAllWritableCalendars方法中。 – Cub71