iOS8错误:ABPersonViewController不显示属性和后退按钮

Rei*_*ner 3 abaddressbook abpersonviewcontroller ios8

以下代码在iOS7中正常工作,但在iOS8中无法正常工作(变量recordID设置正确):

    CFErrorRef error = nil;
    const ABAddressBookRef addressBook = (ABAddressBookCreateWithOptions (NULL, &error));
    ABRecordRef contactRef = ABAddressBookGetPersonWithRecordID (addressBook, recordID);
    ABPersonViewController *personViewController = [[ABPersonViewController alloc] init];
    personViewController.addressBook     = addressBook;
    personViewController.displayedPerson = contactRef;
    CFRelease(addressBook);
    NSArray *displayedProperties = @[@(kABPersonFirstNameProperty),
                                     @(kABPersonLastNameProperty),
                                     @(kABPersonMiddleNameProperty),
                                     @(kABPersonPrefixProperty),
                                     @(kABPersonSuffixProperty),
                                     @(kABPersonOrganizationProperty),
                                     @(kABPersonJobTitleProperty),
                                     @(kABPersonDepartmentProperty),
                                     @(kABPersonEmailProperty),
                                     @(kABPersonBirthdayProperty),
                                     @(kABPersonKindProperty),
                                     @(kABPersonAddressProperty),
                                     @(kABPersonPhoneProperty),
                                     @(kABPersonInstantMessageProperty),
                                     @(kABPersonURLProperty),
                                     @(kABPersonSocialProfileProperty),
                                     @(kABPersonNoteProperty)];
    personViewController.displayedProperties  = displayedProperties;
    personViewController.navigationItem.title = NSLocalizedString(@"CONTACT_DETAILS", nil);
    personViewController.allowsActions        = YES;
    personViewController.allowsEditing        = YES; // if NO, no back button is shown
    personViewController.personViewDelegate   = self;
    personViewController.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"ADDRESSES",nil) style:UIBarButtonItemStylePlain target:self action:@selector(personviewDoneButtonPressed:)];

    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:personViewController];
    [self presentViewController:navigationController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

iOS8中的错误:

  1. allowsEditing被设定为YES,接触被示出,但 仅显示姓名.导航栏左侧显示后退按钮(名为"地址"),右侧显示编辑按钮.按下编辑按钮时,将显示联系人,除名称外所有字段均为空,编辑按钮显示为完成按钮.如果在未进行任何编辑的情况下按下此完成按钮,则会显示有关该联系人的所有信息.
  2. allowsEditing被设定为NO,无返回按钮显示,使画面不再能够留下.

有人解决方法吗?

更新:

我现在意识到,问题1 有时只发生在模拟器上,尽管总是 在我的设备上.

Rei*_*ner 5

montuno(再次感谢),评论我的第一个答案,得到了Apple技术支持如何解决第一个问题的提示,我现在也理解了第二个问题:

1)只显示部分联系人:

Apple声称以下代码错误:

ABRecordRef contactRef = ABAddressBookGetPersonWithRecordID (addressBook, recordID);
ABPersonViewController *personViewController = [[ABPersonViewController alloc] init];
personViewController.addressBook     = addressBook;
personViewController.displayedPerson = contactRef;
CFRelease(addressBook);
Run Code Online (Sandbox Code Playgroud)

addressBook被分配到之后,这里被错误地释放了ABPersonViewController.

在我的原始代码中,我没有CFRelease声明.但随后静态分析仪警告" 存储在addressBook中的对象可能泄漏 ".在我插入release语句之后,构建成功而没有警告,所以我假设personViewController保留了addressBook,显然不是这种情况,至少不是iOS8.我现在再次删除了发布声明,得到了警告,但一切正常.

2)缺少后退按钮:说" 重要人员视图控制器
的文档必须与导航控制器一起使用才能正常工作." ABPersonViewController

所以我所做的是以下内容:
我建立了一个ABPersonViewController,分配给其navigationItem.backBarButtonItem一个" 完成 "按钮,初始化的新UINavigationControllerpersonViewController,使用initWithRootViewController:.然后我提出了新的navigationController模态.
personViewController与返回按钮被显示,并且当被按下时,所述呈现视图控制器驳回模态呈现导航控制器.
这在iOS <8时工作正常,但在iOS8中,后面的按钮没有显示,allowsEditing设置为时NO.

但这显然不是Apple想要展示的方式personViewController:
我认为Apple假定navigationController已经存在,并呈现当前视图,以便新personViewController的只是被推到了堆栈上navigationController.在这种情况下,personViewController不是rootViewControllernavigationController,并且navigationController自动地显示一个后退按钮(未用于进行rootViewController).如果以这种方式实现,一切都适用于iOS8.