【问题标题】:CNUI ERROR Selection predicates are set but the delegate does not implement contactPicker:didSelectContact:CNUI 错误选择谓词已设置,但委托未实现 contactPicker:didSelectContact:
【发布时间】:2015-09-26 21:13:43
【问题描述】:

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

@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");
}
//-----------------------------------------------------------------------

联系人选择器显示为“smith”可选,但我收到以下消息:

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

而且我从来没有从委托方法中得到任何日志。它的行为与这条线完全一样

    contactPicker.delegate = self;

被忽略。即使我点击选择器中的“取消”按钮,我也没有收到“didCancel”消息,但我收到了另一条消息:

com.apple.MobileAddressBook.ContactsViewService 插件失效

我在https://forums.developer.apple.com/thread/12275 发现有人在 swift 中遇到类似问题,他解决了它并告诉我们:“所以我发现我调用的 ContactsPicker 位于错误的模块中” 但我没有了解我们如何获取错误的模块以及如何调用“正确”的模块。

我在模拟器和真实设备 (iPad) 上遇到了同样的问题。

【问题讨论】:

    标签: objective-c contacts ios9


    【解决方案1】:

    感谢 Joel 在我的相关问题 With CNContactPickerViewController in iOS 9.0, how to enable/disable single or multiple selection? 中提出的问题,我发现我只是忘记将 CNContactPickerViewController 存储在用户进行选择时存在的 property 中。

    所以我的代码变成了:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-08
      • 1970-01-01
      • 1970-01-01
      • 2016-06-23
      • 1970-01-01
      • 1970-01-01
      • 2016-10-06
      • 1970-01-01
      相关资源
      最近更新 更多