程序收到Exc_bad_access信号并崩溃

时间:2013-05-21 12:34:08

标签: iphone addressbook

我在访问用户的地址簿时遇到问题。我的代码是

ABMultiValueRef email = ABRecordCopyValue(aSource, kABPersonEmailProperty);
        NSString* email_lbl;
        for(CFIndex i = 0; i < ABMultiValueGetCount(email); i++) {
            email_lbl = (NSString*)ABMultiValueCopyLabelAtIndex(email, i);
            if([email_lbl isEqualToString:(NSString *)kABHomeLabel])
            {
               home_email = [(NSString*)ABMultiValueCopyValueAtIndex(email, i)retain];
            }
            if([email_lbl isEqualToString:(NSString *)kABWorkLabel])
            {
               work_email = [(NSString*)ABMultiValueCopyValueAtIndex(email, i)retain];
            }
            if([email_lbl isEqualToString:(NSString *)kABOtherLabel])
            {
                basic_email = [(NSString*)ABMultiValueCopyValueAtIndex(email, i)retain];
            }

        }

当我记录home_email,work_email,basic_email时收到Exc_bad_access信号。

1 个答案:

答案 0 :(得分:0)

我找到了解决这个问题的方法。我声明了home_email,work_email,basic_email但没有初始化它们,当我在日志中打印它们时,它们没有被初始化。 这解决了我的问题。