When filling in new contact information I want to show the user an ABNewPersonViewController that does not contain all default fields. I cannot figure out how to accomplish this. Is it possible to hide some fields or do I need to write my own view controller?
Asked
Active
Viewed 456 times
2 Answers
0
No, you cannot hide fields from the view controller, as Apple wants to be it the same through all iOS apps. So for customized behaviour, you'll have write your own view controller and add the contact programmatically
For a reference see: How to add new contact to iOS Address Book?
0
You can set the values which are initially displayed for the new contact by setting the displayPerson
property to an ABRecordRef
which you allocate. Simply set the fields of the ABRecordRef
to the values you want.
Example:
ABNewPersonViewController *newPersonController =
[[ABNewPersonViewController alloc] init];
newPersonController.newPersonViewDelegate = self;
ABRecordRef newPerson = ABPersonCreate();
NSString *number =
[AFEndPoint normalizePhoneAddress:[self.historyParticipant participant].endPointValue ];
CFTypeRef phoneProperty = ABMultiValueCreateMutable(kABStringPropertyType);
if (phoneProperty) {
ABMultiValueRef multi = ABMultiValueCreateMutableCopy(phoneProperty);
if (multi) {
ABMultiValueAddValueAndLabel(
multi,
(__bridge CFStringRef)number,
kABPersonPhoneMobileLabel,
nil);
ABRecordSetValue(newPerson, kABPersonPhoneProperty, multi, nil);
CFRelease(multi);
}
CFRelease(phoneProperty);
}
newPersonController.displayedPerson = newPerson;