Apple提供了一个很好的全面和小例子,“QuickContacts”(
developer.apple.com/library/IOs/samplecode/QuickContacts/Introduction/Intro.html),概述了
Address Book UI Framework的基本用法. – 可下载的源代码按照描述进行工作(一旦将名为“Appleseed”的人添加到您的通讯簿或更改人名在第246行(QuickContactsViewController.m)到你的地址簿中已经存在的东西).
题:
我们如何修改函数 – (void)showPersonViewController函数,使得ABPersonViewController“选择器”已经处于编辑模式(具有可见的“Done”editingButton),当它打开时(被推送到navigationController的堆栈之后) .
在“7”之前的iOS版本中,这是一个简单的例子. picker.editing = YES;在将选择器推送到导航堆栈之前,为了在编辑模式中看到它,一旦打开(参见下面的代码).
在iOS7中,这不再工作了.
这是iOS7中的错误,是否有简单的解决方法(而不是ABPersonViewController类的反向工程)? – 还是需要编码不同,这几天?
期待您的意见.
-(void)showPersonViewController { // Search for the person named "Appleseed" in the address book NSArray *people = (NSArray *)CFBridgingRelease(ABAddressBookCopyPeopleWithName(self.addressBook,CFSTR("Appleseed"))); // Display "Appleseed" information if found in the address book if ((people != nil) && [people count]) { ABRecordRef person = (__bridge ABRecordRef)[people objectAtIndex:0]; ABPersonViewController *picker = [[ABPersonViewController alloc] init]; picker.personViewDelegate = self; picker.displayedPerson = person; // Allow users to edit the person’s information picker.allowsEditing = YES; picker.editing = YES; // in iOS6 this works,in iOS7 it does not [self.navigationController pushViewController:picker animated:YES]; } ... ... }
解决方法
您可以使用ABNewPersonViewController代替ABPersonViewController,下面是代码:
ABNewPersonViewController *picker = [[[ABNewPersonViewController alloc] init] autorelease]; picker.newPersonViewDelegate = self; picker.displayedPerson = person; picker.navigationItem.title=@"edit contact"; [self.navigationController pushViewController:picker animated:YES];