0

I'm getting this error when trying to open the "Contacts" app view within my app for selecting and importing contacts. I'm not sure what the issue is. Can someone help solve the problem?

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController openContacts:]: unrecognized selector sent to instance 0x7ff917a10740'

Here's my code

let contact = CNMutableContact()

var delegate: ViewSevenFiveDelegate!

var tableViewController: ViewTwo? = nil

//Fetch Contacts Information like givenName and familyName, phoneNo, address
let keysToFetch = [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactPhoneNumbersKey]

let store = CNContactStore()

@IBAction func openContacts(sender: AnyObject) {
    //open contacts to add to VCtable

    let contactPickerViewController = CNContactPickerViewController()

    contactPickerViewController.predicateForEnablingContact = NSPredicate(format: "Number != nil")

    contactPickerViewController.displayedPropertyKeys = [CNContactGivenNameKey, CNContactFamilyNameKey, CNContactPhoneNumbersKey]

    contactPickerViewController.delegate = self

    presentViewController(contactPickerViewController, animated: true, completion: nil)
}

func contactPicker(picker: CNContactPickerViewController, didSelectContact contact: CNContact) {
    delegate.didFetchContacts([contact])
    navigationController?.popViewControllerAnimated(true)
}

}

jonB22
  • 5
  • 4
  • It seems your openContacts action is not recognizable. How have you created thw button and its connection. Also when you create a button action sender should be a UIButton not AnyObject though its not an error. – Arun Gupta Apr 02 '16 at 08:45
  • I believe I created the button properly. I first added the button to my storyboard and then control dragged it to my swift file. I also made sure that the outlet was connected properly and that I spelled it correctly. And thanks for the UIButton tip! – jonB22 Apr 02 '16 at 10:27
  • Put a breakpoint on the method and see if its getting called – Arun Gupta Apr 02 '16 at 11:50
  • I found the error, an old outlet that still was connected somehow. – jonB22 Apr 03 '16 at 03:31
  • That happens most of the time. – Arun Gupta Apr 03 '16 at 04:38

0 Answers0