我有这样的属性集:
.h file
@property(nonatomic, strong) NSArray *writableCalendars;
- (NSArray *)getWritableCalendars;
.m file
@synthesize writableCalendars;
- (void)viewDidLoad
{
[super viewDidLoad];
[self setWritableCalendars:[self getWritableCalendars]];
}
- (NSArray *)getWritableCalendars
{
NSMutableArray *_writableCals = [NSMutableArray array];
EKEventStore *eventDB = [[EKEventStore alloc]init];
NSArray *allCals = [eventDB calendars];
for (EKCalendar *denne in allCals)
{
if ([denne allowsContentModifications])
{
[_writableCals addObject:denne];
}
}
NSLog(@"_writeables: %@", _writableCals);
allCals = nil;
eventDB = nil;
return [NSArray arrayWithArray: _writableCals];
}
我在这里使用数组:
- (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)
{
EKCalendar *denneCal = [[self writableCalendars] objectAtIndex:[indexPath row]];
NSString *calName = [denneCal title];
cell.textLabel.text = calName;
}
else
{
cell.textLabel.text = @"No calendars found";
}
return cell;
}
奇怪的是,这现在有效,但如果我在' getWritableCalendars'中注释掉NSLog语句。方法,日历标题在< cellForRowAtIndexPath'
中为零我错过了什么?