本文主要是介绍AddressBookUI.Framwork应用之ABPersonViewController, ABUnknownPersonViewController,ABNewPersonViewContro,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
设置委托 ABPersonViewControllerDelegate,personVc.personViewDelegate=self;
//显示和编辑一个联系人信息
ABPersonViewController *personVc=[[ABPersonViewControlleralloc]init];
//把联系人信息作为导航栏的根视图,才可以显示编辑按钮和 完成按钮,返回按钮
UINavigationController *nav=[[UINavigationControlleralloc]initWithRootViewController:personVc];
ABRecordRef person=ABPersonCreate();
//CFString=CFSTR("")类似NSString =@"";直接赋值
ABRecordSetValue(person, kABPersonFirstNameProperty, CFSTR("jun"), NULL);
ABRecordSetValue(person, kABPersonLastNameProperty, CFSTR("ye"), NULL);
personVc.personViewDelegate=self;
personVc.displayedPerson=person;
CFRelease(person);
personVc.allowsEditing=YES;
委托方法:
-(BOOL)personViewController:(ABPersonViewController *)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
return NO ;//不为默认操作
}
//添加新联系人到通讯录,一般用于通讯录外面的应用,比如说点击某个按钮,直接进入联系人编辑,然后添加到通讯录
ABUnknownPersonViewController *unknown=[[ABUnknownPersonViewController alloc]init];
unknown.displayedPerson=person;
unknown.allowsAddingToAddressBook=YES;//允许添加
//委托方法
-(BOOL)unknownPersonViewController:(ABUnknownPersonViewController*)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
return NO;
}
//新建联系人,允许用户填入一个新联系人的所有属性,一般是通讯录里面的新建
ABNewPersonViewController *new=[[ABNewPersonViewControlleralloc]init];
new.newPersonViewDelegate=self;
//委托方法
-(void)newPersonViewController:(ABNewPersonViewController*)newPersonView didCompleteWithNewPerson:(ABRecordRef)person
{
//用于编辑新联系人后做的事件,比如说模态退出,比如说不保存联系人到通讯录
if (person!=NULL) {
ABAddressBookRef adbk=ABAddressBookCreate();
//从数据库中删除新加的联系人
ABAddressBookRemoveRecord(adbk, person, NULL);
CFStringRef name=ABRecordCopyCompositeName(person);
NSLog(@"name%@",name);//对新加的联系人做处理,不一定要保存到通讯录数据库
CFRelease(name);
CFRelease(adbk);
}
}
这篇关于AddressBookUI.Framwork应用之ABPersonViewController, ABUnknownPersonViewController,ABNewPersonViewContro的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!