我無法正常訪問我的聯繫人的地址屬性。我能夠使用下面的方法成功訪問電話號碼或地址,但是當獲取地址屬性時,我會在負責框架處發生泄漏,並顯示「+ [ABStyleProvider]」。任何人都可以告訴我這是什麼意思或我做錯了什麼?內存泄漏使用AddressBook:泄漏對象「ABStyleProvider」
下面是ABPeoplePickerNavigationController。以下是我如何處理電話號碼或地址的選擇。我使用NSMutableString和CFDictionaryGetValueIfPresent來僅收集非空數據並將其作爲字符串返回。
感謝您的幫助和任何建議,將不勝感激。
if (person) {
if (property == kABPersonPhoneProperty){
ABMultiValueRef phones = ABRecordCopyValue(person, kABPersonPhoneProperty); //Dane
if (phones) {
CFIndex index = ABMultiValueGetIndexForIdentifier(phones, identifier);
NSString *phone = (NSString*)ABMultiValueCopyValueAtIndex(phones, index);
//Set textField with Phone Number
MyTextField.text = phone;
[phone release];
CFRelease(phones);
[self doneEnteringPhoneNumber];
}
}
else if (property == kABPersonAddressProperty){
ABMultiValueRef addresses = ABRecordCopyValue(person, kABPersonAddressProperty); //Dane
if (addresses) {
CFIndex index = ABMultiValueGetIndexForIdentifier(addresses, identifier);
CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(addresses, index);
//Get Only valid address values (Non-Null)
CFTypeRef aString;
NSMutableString * address = [NSMutableString string];
if (CFDictionaryGetValueIfPresent(dict, kABPersonAddressStreetKey, &aString)){
[address appendString:[NSString stringWithFormat:@"%@ ",(NSString *)aString]];
}
if (CFDictionaryGetValueIfPresent(dict, kABPersonAddressCityKey, &aString)){
[address appendString:[NSString stringWithFormat:@"%@ ",(NSString *)aString]];
}
if (CFDictionaryGetValueIfPresent(dict, kABPersonAddressStateKey, &aString)){
[address appendString:[NSString stringWithFormat:@"%@ ",(NSString *)aString]];
}
if (CFDictionaryGetValueIfPresent(dict, kABPersonAddressZIPKey, &aString)){
[address appendString:[NSString stringWithFormat:@"%@ ",(NSString *)aString]];
}
CFRelease(dict);
//Set Address
DestinationTextField.text = address;
CFRelease(addresses);
//Auto trigger search for address
[self doneEnteringAddress];
}
}
}
作爲後續,我完全刪除所有代碼,只是顯示,並在下列情況下,駁回了peoplePickerController: 1.如果一個人選擇 2.如果屬性選擇 3.如果用戶取消 並在每種情況下,我看到上述內存泄漏。
儀器擴展詳細泄漏:(16字節)。每次回到我的主視圖都會泄漏?
0 libSystem.B.dylib calloc
1 libobjc.A.dylib _internal_class_createInstanceFromZone
2 libobjc.A.dylib class_createInstance
3 CoreFoundation +[NSObject(NSObject) allocWithZone:]
4 CoreFoundation +[NSObject(NSObject) alloc]
5 CoreFoundation +[NSObject(NSObject) new]
6 AddressBookUI +[ABStyleProvider defaultStyleProvider]
7 AddressBookUI -[ABPeoplePickerNavigationController initAsAddressBook:withAddressBook:]
8 AddressBookUI -[ABPeoplePickerNavigationController init]
9 Cartis -[MainViewController getContactPhoneNumber:] ****************.m:707
10的CoreFoundation - [NSObject的(NSObject的)performSelector:withObject:withObject:]
除了這裏是我的PeoplePicker初始化和從IBAction爲方法
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.peoplePickerDelegate = self;
NSArray * displayedProperties = [NSArray arrayWithObjects:
[NSNumber numberWithInt:kABPersonPhoneProperty],
[NSNumber numberWithInt:kABPersonAddressProperty],
nil];
picker.displayedProperties = displayedProperties;
//Dane - here
[self presentModalViewController:picker animated:YES];
[picker release];
作爲一個後續,我完全刪除了所有這些代碼,只是在以下情況下顯示和解除了peoplePickerController: – user582546 2011-01-21 07:59:15