こんにちは私はiOSデザインとSwiftを初めて使いました。単純な連絡先選択ツールを実装しようとしています。 View Controllerにボタンがあり、View ControllerはCNContactPickerDelegateに準拠していますが、アプリケーションを実行してピッカーを使用すると、contactPickerDidCancel関数とcontactPicker関数がピッカー内の何を押しても決して呼び出されません。私が理解する限り、ピッカーは、彼がピッカー内のボタンまたは連絡先をキャンセルしないでクリックすると、私が書いた関数を呼び出す必要があります。これは間違っていますか?どんな助けやアイデアも素晴らしいでしょう!ありがとう!contactPickerDidCancelとcontactPicker関数は呼び出されません
更新:解決済み。これは単純な構文エラーでした。どちらの関数でも、私は "ピッカー"の前にアンダースコアを付けませんでした。
@IBAction func addContactPressed(_ sender: Any) {
let contactPickerViewController = CNContactPickerViewController()
contactPickerViewController.delegate = self
contactPickerViewController.predicateForEnablingContact = NSPredicate(format: "[email protected] > 0", argumentArray: nil)
contactPickerViewController.predicateForSelectionOfProperty =
NSPredicate(format: "key == 'phoneNumbers'", argumentArray: nil)
contactPickerViewController.displayedPropertyKeys = [CNContactEmailAddressesKey, CNContactPhoneNumbersKey]
self.present(contactPickerViewController, animated: true, completion: nil)
}
func contactPickerDidCancel(picker: CNContactPickerViewController) {
print("Cancelled picking a contact.")
}
func contactPicker(picker: CNContactPickerViewController, didSelectContact contact: CNContact) {
print("Selected a contact.")
if contact.isKeyAvailable(CNContactPhoneNumbersKey) {
print(contact.phoneNumbers)
}
else {
print("No phone numbers are available.")
}
}
あなたのクラスはそのデリゲートに準拠していますか? – Shachar