viewControllerForNewContact显示所有键

时间:2016-03-23 20:34:56

标签: ios objective-c cncontactviewcontroller

我想在创建新的CNContact时使用有限数量的键(利用viewControllerForNewContact方法)。然而,尽管我尝试过获取键的各种值,但我仍然可以获得整个可设置值的范围。我们如何限制为新联系人显示的密钥?

对于现有的联系人来说,这似乎工作得很好,但不管怎么说不适合新的联系人......

以下是我的代码......

    CNMutableContact *newContact = [[CNMutableContact alloc] init];

    // NSArray *keysToFetch = @[CNContactGivenNameKey, CNContactFamilyNameKey, CNContactPhoneNumbersKey, CNContactEmailAddressesKey, CNContactImageDataKey, [CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName], [CNContactViewController descriptorForRequiredKeys]];
    // NSArray *keysToFetch = @[[CNContactViewController descriptorForRequiredKeys]];
    // NSArray *keysToFetch = @[CNContactGivenNameKey, [CNContactViewController descriptorForRequiredKeys]];
    // NSArray *keysToFetch = @[CNContactIdentifierKey, CNContactEmailAddressesKey, CNContactBirthdayKey, CNContactImageDataKey, CNContactPhoneNumbersKey, [CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName],[CNContactViewController descriptorForRequiredKeys]];
    // NSArray *keysToFetch = @[[CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName], CNContactEmailAddressesKey];
    NSArray *keysToFetch = @[CNContactGivenNameKey, CNContactPhoneNumbersKey];

    CNContactViewController *newContactViewController = [CNContactViewController viewControllerForNewContact:newContact];

    newContactViewController.delegate = self;
    newContactViewController.allowsActions = YES;
    newContactViewController.allowsEditing = YES;
    newContactViewController.displayedPropertyKeys = keysToFetch;

    UINavigationController *newContactNavViewController = [[UINavigationController alloc] initWithRootViewController:newContactViewController];
    newContactNavViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentViewController:newContactNavViewController animated:YES completion:nil];

1 个答案:

答案 0 :(得分:0)

在头文件CNContactViewController.h中,有一条说明:“编辑联系人时所有属性都可见”。所以我想它不会改变为新联系人设置displayedPropertyKeys的任何内容,因为它将以编辑模式显示。