CNUI错误选择谓词已设置,但委托未实现contactPicker:didSelectContact: [英] CNUI ERROR Selection predicates are set but the delegate does not implement contactPicker:didSelectContact:

查看:93
本文介绍了CNUI错误选择谓词已设置,但委托未实现contactPicker:didSelectContact:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用新的iOS 9.0 CNContactPickerViewController 在Objective-C中选择一个联系人.我设置了委托并实现了 CNContactPickerDelegate 方法.

I try to use the new iOS 9.0 CNContactPickerViewController to select a contact in objective-C. I set the delegate and implement the CNContactPickerDelegate methods.

@import ContactsUI;
@import Contacts;
//-----------------------------------------------------------------------
- (void) presentContacts
{
    CNContactPickerViewController *contactPicker = [[CNContactPickerViewController alloc] init];
    contactPicker.delegate = self;
    contactPicker.predicateForEnablingContact = [NSPredicate predicateWithFormat:@"familyName LIKE[cd] 'smith'"];
    contactPicker.predicateForSelectionOfContact = [NSPredicate predicateWithFormat:@"TRUEPREDICATE"];
    [_myViewController presentViewController:contactPicker animated:YES completion:nil];
}
//-----------------------------------------------------------------------
- (void) contactPickerDidCancel: (CNContactPickerViewController *) picker
{
    NSLog(@"didCancel");
}
//-----------------------------------------------------------------------
- (void) contactPicker: (CNContactPickerViewController *) picker
      didSelectContact: (CNContact *)                     contact
{
    NSLog(@"didSelectContact"):
}
//-----------------------------------------------------------------------
- (void)      contactPicker: (CNContactPickerViewController *) picker
   didSelectContactProperty: (CNContactProperty *)             contactProperty
{
    NSLog(@"didSelectProperty");
}
//-----------------------------------------------------------------------

联系人选择器显示为史密斯"可选,但我收到以下消息:

The contacts picker is presented with 'smith' selectable but I get the following message:

[CNUI错误]已设置选择谓词,但委托未实现contactPicker:didSelectContact:和contactPicker:didSelectContactProperty:.这些谓词将被忽略.

而且我从来没有从委托方法中得到任何日志.它的行为与线条完全相同

And I never get any log from the delegate methods. It behaves exactly as the line

    contactPicker.delegate = self;

被忽略.即使我单击选择器中的取消"按钮,也没有收到"didCancel"消息,但又收到了另一条消息:

is ignored. Even I click on the "cancel" button in the picker, I don't get my "didCancel" message but I get another message:

插件com.apple.MobileAddressBook.ContactsViewService无效

我发现在 https://forums.developer.apple.com/thread/12275很快遇到类似问题的人,他解决了这个问题并告诉我们:因此,我发现我正在呼叫的ContactsPicker位于错误的模块中" ,但我不明白我们怎么能得到错误的信息模块以及如何调用正确的"模块.

I found in https://forums.developer.apple.com/thread/12275 somebody with the similar problem in swift and he solved it telling us: "So I found that the ContactsPicker I was calling was in the wrong module" but I do not understand how we can get the wrong module and how to call the "right" module.

在模拟器和真实设备(iPad)上,我也遇到相同的问题.

I have the same problem on the simulator and on a real device (iPad).

推荐答案

感谢乔尔在我的相关问题中

Thanks to Joel in my related question With CNContactPickerViewController in iOS 9.0, how to enable/disable single or multiple selection?, I found that I just forgot to store the CNContactPickerViewController in a property that exists the time the user make the selection.

所以我的代码变成:

- (void) presentContacts
{
    _contactPicker = [[CNContactPickerViewController alloc] init];
    contactPicker.delegate = self;
    ...
}

这篇关于CNUI错误选择谓词已设置,但委托未实现contactPicker:didSelectContact:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆