2011-10-15 50 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