내 iPad 2의 주소록에 액세스하는 데 문제가 있습니다. 특히 연락처의 이메일을 검색하는 데 문제가 있습니다. 내가하고 싶은 일은 주소록에 액세스하고 연락처를 검색하여 테이블보기로 표시하는 것입니다. 연락처의 이름과 성이 표시되기 때문에 모든 것이 잘된 것처럼 보입니다. 문제는 이메일 속성을 검색 할 때 "EXC_BAD_ACCESS"가 표시되기 때문에 이메일 속성 때문입니다. 내가있는 tableview 기록을 보여주기 위해 쓴 코드는 다음ABMultiValueRef의 iOS 주소록 오류
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *tableIdentifier = @"tableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:tableIdentifier] autorelease];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
NSUInteger row = [indexPath row];
NSString *firstName = (NSString *)ABRecordCopyValue([contacts objectAtIndex:row], kABPersonFirstNameProperty);
NSString *lastName = (NSString *)ABRecordCopyValue([contacts objectAtIndex:row], kABPersonLastNameProperty);
NSString *name = [[NSString alloc] initWithFormat:@"%@ %@", lastName,firstName];
[firstName release];
[lastName release];
cell.textLabel.text = name;
[name release];
NSArray *emails = [[self getEmailForPerson:row] retain];
/*......*/
return cell;
}
함수가 내 연락처의 이메일을하면서는 다음과 같다
- (NSArray *)getEmailForPerson:(NSInteger)index{
//Create the array where emails will be stored
NSMutableArray *m = [[[NSMutableArray alloc] init] autorelease];
//Get the email properties
ABMultiValueRef mails = ABRecordCopyValue([self.contacts objectAtIndex:index], kABPersonEmailProperty);
//Iterate in the multi-value properties
for (int i=0; i<ABMultiValueGetCount(mails); i++) {
//Get the email
NSString *mail = (NSString *) ABMultiValueCopyValueAtIndex(mails, i);
//Add the email to the array previously initializated
[m addObject:mail];
[mail release];
}
CFRelease(mails);
return m;
}
나는이 문 다음에 디버거를 실행하면 그 ADRESS은 0x0으로이기 때문에
ABMultiValueRef mails = ABRecordCopyValue([self.contacts objectAtIndex:index], kABPersonEmailProperty);
메일은 초기화되지 않은 것 같다하지만 난 이유를 이해할 수 없다. 누군가 나를 도울 수 있기를 바랍니다. 그것은 내 응용 프로그램에서 잘 작동 미리
동일한 문제가 있습니다. 이유를 발견 한 적이 있습니까? – DexterW