NSArray свойства со странным поведением - PullRequest
0 голосов
/ 11 ноября 2011

У меня есть свойство, установленное так:

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

Странно то, что теперь это работает, но если я закомментирую оператор NSLog в методе 'getWritableCalendars', заголовок календаря будет равен нулю в 'cellForRowAtIndexPath'

Чего мне не хватает?

...