2

我已经意识到,如果我使用委托方法contactPicker:didSelectContact来呈现自定义CNContactViewControllercontactPicker:didSelectContactProperty则不再调用该方法。

func openPicker() {
    let picker = CNContactPickerViewController()
    picker.delegate = self
    self.presentViewController(picker, animated: true, completion: nil)
}

func contactPicker(picker: CNContactPickerViewController, didSelectContact contact: CNContact) { 
    //contactPicker:didSelectContactProperty works when this method is commented out

    let controller = CNContactViewController(forContact: contact)
    controller.delegate = self
    self.navigationController?.pushViewController(controller, animated: true)
}

func contactViewController(viewController: CNContactViewController, shouldPerformDefaultActionForContactProperty property: CNContactProperty) -> Bool {

    return false
}

func contactPicker(picker: CNContactPickerViewController, didSelectContactProperty contactProperty: CNContactProperty) {

    print("selected contact property")
}

当用户选择属性时,如何呈现自定义CNContactViewController 并收到通知?

使用contactViewController:shouldPerformDefaultActionForContactProperty来记录选定的数据确实有效,但它似乎是对该方法的滥用。

4

0 回答 0