-1

我有下一个代码:

-(void)accountAdded:(GoogleMailAccount *)account
{
    DLog(@"accountAdded %@ ",account.emailAddress);

     DLog(@"_accounts addObject %@ ",account);
    [_accounts addObject:account];

     DLog(@"_accounts count %d",[_accounts count]);

    [_subFolders setValue:[account subscribedFolders] forKey:account.emailAddress];

    [self refreshTableViewTree];
}

以及它的下一个日志输出:

2013-08-02 00:57:28.009 MailClient[9327:11603] accountAdded iosmailclienttest@gmail.com 
2013-08-02 00:57:28.010 MailClient[9327:11603] _accounts addObject <GoogleMailAccount: 0x7db94f0> 
2013-08-02 00:57:28.011 MailClient[9327:11603] _accounts count 0

为什么帐户大小 = 0?(这对我来说是一个真正的问题:(。我没有看到什么???)

4

1 回答 1

3

在方法的开始:

 if(!_accounts) _accounts = [[NSMutableArray alloc]init];

或者你可以这样做:

-(NSMutableArray *)accounts
{
    if(!_accounts) _accounts = [[NSMutableArray alloc]init];
    return _accounts;
}
于 2013-08-01T22:09:50.433 回答