AddressBook UI contact 联系簿(UI) 官方demo
来源:互联网 发布:cnnic管理的通用域名 编辑:程序博客网 时间:2024/06/06 20:33
转载请说明:(谢谢)
http://blog.csdn.net/a21064346/article/details/8021842
点击打开链接
对于系统的contact 联系簿的ViewController 如何使用,下面又一个官方的demo,大家可以拿去看看。
这个东西,找了一段时间。其实不是很难,配合自己写的数据模型,很容易就能做出好的功能。只不过UI这块就要差一点了。
下面是一个类的h和m文件,大家自己把他搭建好,app delegate自己搭下,加入到一个NavigationController中即可。不需要其他的controller,只需要在导入两个系统的frame。
对于一些 contact 联系簿的controller,这里可以调用,不需要再去自己设计出 一个 很复杂的 contact了(本人尝试写了3000+的ui逻辑还没有实现它的全部功能,如果有人写出来了,或者网上有代码,希望可以学习下:),在此感激不尽)
#import <UIKit/UIKit.h>#import <AddressBook/AddressBook.h>#import <AddressBookUI/AddressBookUI.h>@interface QuickContactsViewController : UITableViewController < ABPeoplePickerNavigationControllerDelegate, ABPersonViewControllerDelegate, ABNewPersonViewControllerDelegate, ABUnknownPersonViewControllerDelegate>{NSMutableArray *menuArray;}@property (nonatomic, retain) NSMutableArray *menuArray;-(void)showPeoplePickerController;-(void)showPersonViewController;-(void)showNewPersonViewController;-(void)showUnknownPersonViewController;@end
#import "QuickContactsViewController.h"enum TableRowSelected {kUIDisplayPickerRow = 0,kUICreateNewContactRow,kUIDisplayContactRow,kUIEditUnknownContactRow};// Height for the Edit Unknown Contact row#define kUIEditUnknownContactRowHeight 81.0@implementation QuickContactsViewController@synthesize menuArray;#pragma mark Load views// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.- (void)viewDidLoad {[super viewDidLoad];// Load data from the plist fileNSString *plistPath = [[NSBundle mainBundle] pathForResource:@"Menu" ofType:@"plist"];self.menuArray = [NSMutableArray arrayWithContentsOfFile:plistPath];}#pragma mark Unload views- (void)viewDidUnload {self.menuArray = nil; [super viewDidUnload];}#pragma mark Table view methods- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{return [menuArray count];}// Customize the number of rows in the table view.- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1;}// Customize the appearance of table view cells.- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *aCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];if (aCell == nil){// Make the Display Picker and Create New Contact rows look like buttonsif (indexPath.section < 2){aCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];aCell.textLabel.textAlignment = UITextAlignmentCenter;}else{aCell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];aCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;aCell.detailTextLabel.numberOfLines = 0;// Display descriptions for the Edit Unknown Contact and Display and Edit Contact rows aCell.detailTextLabel.text = [[menuArray objectAtIndex:indexPath.section] valueForKey:@"description"];}}aCell.textLabel.text = [[menuArray objectAtIndex:indexPath.section] valueForKey:@"title"];return aCell;}- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {switch (indexPath.section){case kUIDisplayPickerRow:[self showPeoplePickerController];break;case kUICreateNewContactRow:[self showNewPersonViewController];break;case kUIDisplayContactRow:[self showPersonViewController];break;case kUIEditUnknownContactRow:[self showUnknownPersonViewController];break;default:[self showPeoplePickerController];break;}}#pragma mark TableViewDelegate method- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{// Change the height if Edit Unknown Contact is the row selectedreturn (indexPath.section==kUIEditUnknownContactRow) ? kUIEditUnknownContactRowHeight : tableView.rowHeight;}#pragma mark Show all contacts// Called when users tap "Display Picker" in the application. Displays a list of contacts and allows users to select a contact from that list.// The application only shows the phone, email, and birthdate information of the selected contact.-(void)showPeoplePickerController{ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init]; picker.peoplePickerDelegate = self;// Display only a person's phone, email, and birthdateNSArray *displayedItems = [NSArray arrayWithObjects:[NSNumber numberWithInt:kABPersonPhoneProperty], [NSNumber numberWithInt:kABPersonEmailProperty], [NSNumber numberWithInt:kABPersonBirthdayProperty], nil];picker.displayedProperties = displayedItems;// Show the picker [self presentModalViewController:picker animated:YES]; [picker release];}#pragma mark Display and edit a person// Called when users tap "Display and Edit Contact" in the application. Searches for a contact named "Appleseed" in // in the address book. Displays and allows editing of all information associated with that contact if// the search is successful. Shows an alert, otherwise.-(void)showPersonViewController{// Fetch the address book ABAddressBookRef addressBook = ABAddressBookCreate();// Search for the person named "Appleseed" in the address bookNSArray *people = (NSArray *)ABAddressBookCopyPeopleWithName(addressBook, CFSTR("1"));// Display "Appleseed" information if found in the address book if ((people != nil) && [people count]){ABRecordRef person = (ABRecordRef)[people objectAtIndex:0];ABPersonViewController *picker = [[[ABPersonViewController alloc] init] autorelease];picker.personViewDelegate = self;picker.displayedPerson = person;// Allow users to edit the person’s informationpicker.allowsEditing = YES;[self.navigationController pushViewController:picker animated:YES];}else {// Show an alert if "Appleseed" is not in ContactsUIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Could not find Appleseed in the Contacts application" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil];[alert show];[alert release];}[people release];CFRelease(addressBook);}#pragma mark Create a new person// Called when users tap "Create New Contact" in the application. Allows users to create a new contact.-(void)showNewPersonViewController{ABNewPersonViewController *picker = [[ABNewPersonViewController alloc] init];picker.newPersonViewDelegate = self;UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:picker];[self presentModalViewController:navigation animated:YES];[picker release];[navigation release];}#pragma mark Add data to an existing person// Called when users tap "Edit Unknown Contact" in the application. -(void)showUnknownPersonViewController{ABRecordRef aContact = ABPersonCreate();CFErrorRef anError = NULL;ABMultiValueRef email = ABMultiValueCreateMutable(kABMultiStringPropertyType);bool didAdd = ABMultiValueAddValueAndLabel(email, @"John-Appleseed@mac.com", kABOtherLabel, NULL);if (didAdd == YES){ABRecordSetValue(aContact, kABPersonEmailProperty, email, &anError);if (anError == NULL){ABUnknownPersonViewController *picker = [[ABUnknownPersonViewController alloc] init];picker.unknownPersonViewDelegate = self;picker.displayedPerson = aContact;picker.allowsAddingToAddressBook = YES; picker.allowsActions = YES;picker.alternateName = @"John Appleseed";picker.title = @"John Appleseed";picker.message = @"Company, Inc";[self.navigationController pushViewController:picker animated:YES];[picker release];}else {UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Could not create unknown user" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil];[alert show];[alert release];}}CFRelease(email);CFRelease(aContact);}#pragma mark ABPeoplePickerNavigationControllerDelegate methods// Displays the information of a selected person- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person{return YES;}// Does not allow users to perform default actions such as dialing a phone number, when they select a person property.- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{return NO;}// Dismisses the people picker and shows the application when users tap Cancel. - (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker;{[self dismissModalViewControllerAnimated:YES];}#pragma mark ABPersonViewControllerDelegate methods// Does not allow users to perform default actions such as dialing a phone number, when they select a contact property.- (BOOL)personViewController:(ABPersonViewController *)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifierForValue{return NO;}#pragma mark ABNewPersonViewControllerDelegate methods// Dismisses the new-person view controller. - (void)newPersonViewController:(ABNewPersonViewController *)newPersonViewController didCompleteWithNewPerson:(ABRecordRef)person{[self dismissModalViewControllerAnimated:YES];}#pragma mark ABUnknownPersonViewControllerDelegate methods// Dismisses the picker when users are done creating a contact or adding the displayed person properties to an existing contact. - (void)unknownPersonViewController:(ABUnknownPersonViewController *)unknownPersonView didResolveToPerson:(ABRecordRef)person{[self dismissModalViewControllerAnimated:YES];}// Does not allow users to perform default actions such as emailing a contact, when they select a contact property.- (BOOL)unknownPersonViewController:(ABUnknownPersonViewController *)personViewController shouldPerformDefaultActionForPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{return NO;}#pragma mark Memory management- (void)dealloc {[menuArray release]; [super dealloc];}@end
- AddressBook UI contact 联系簿(UI) 官方demo
- AddressBook UI 官方demo (IOS)
- UI - UITableViewEdit,Contact
- ABAddressBook & AddressBook UI 文件介绍(IOS开发)
- ABAddressBook & AddressBook UI 文件介绍(IOS开发)
- BaiduMap---百度地图官方Demo之UI控制功能(介绍开关手势功能和显示隐藏UI控件)
- BaiduMap---百度地图官方Demo之UI控制功能(介绍开关手势功能和显示隐藏UI控件)
- iOS开发------操作通讯录(AddressBook篇)&通讯录UI(AddressBookUI篇)
- 操作通讯录(AddressBook篇)&通讯录UI(AddressBookUI篇)
- ReactNative Demo - 仿携程UI Demo
- react native(七) 界面 UI-demo
- jQuery UI Tabs Demo
- 很好的UI Demo
- jquery ui datepicker demo
- JQuery UI dialog Demo
- UI更新demo
- Android UI设计,google官方
- Android UI”设计官方教程
- html Frame、Iframe、Frameset 的区别
- javascript固定时间操作器
- 房讯房屋租赁管理软件新版上线 专为房东朋友定制
- android工程字符串多语言翻译遗漏查找工具
- eval解析JSON中的注意点
- AddressBook UI contact 联系簿(UI) 官方demo
- paip.提升用户体验---程序异常处理
- android锁屏后wifi不活跃的解决方案
- 你不得不知道的Visual Studio 2012(2)- 全新调试功能
- 线性表的知识,插入操作
- Android 一个强大实用的版本升级demo(thread+service+Notification)
- ffmpeg常用参数一览表
- OPNET信道模型概述
- 优秀技术博客