I came to know that search bar in CNContactPickerViewController
doesn't allow to select searched contacts. I also look other stack overflow questions regarding this issue. It seems like iOS bug. But I want to know, is there any way to hide or disable search bar from CNContactPickerViewController
? Because if this doesn't work then I don't want to show it.
Asked
Active
Viewed 1,141 times
3

Dávid Pásztor
- 51,403
- 9
- 85
- 116

Richa Gupta
- 31
- 3
-
please see this https://stackoverflow.com/questions/17141210/how-to-hide-remove-the-search-bar-on-contact-picker – Saurabh Jain Jul 21 '17 at 03:55
-
Saurabh, that is in objective-c, i need the response in swift 3. – Richa Gupta Jul 26 '17 at 17:30
-
I have the same issue, I wish to hide the search bar on the CNContactPickerViewController because the search box is useless! – Plasma Sep 22 '17 at 16:31
-
It's not useless when you have 300 contacts ... – Softlion Oct 05 '17 at 10:23
2 Answers
0
private var foundSearchBar: Bool = false
func findSearchBar(_ parent: UIView, mark: String) {
for v: UIView in parent.subviews {
//if( foundSearchBar ) return;
print("\(mark)\(NSStringFromClass(v.self))")
if (v is UISearchBar) {
(v as? UISearchBar)?.tintColor = UIColor.black
v.hidden = true
// foundSearchBar = YES;
break
}
if (v is UITableView) {
let temp: CGRect = v.frame
temp.origin.y = temp.origin.y - 44
temp.size.height = temp.size.height + 44
v.frame = temp
//foundSearchBar = YES;
break
}
findSearchBar(v, mark: mark + ("> "))
}
}
call above method after picker is presented as below:
func showPeoplePickerController() {
let picker = ABPeoplePickerNavigationController()
picker.peoplePickerDelegate = self
picker.view.autoresizingMask = .flexibleHeight
// Display only a person's phone, email, and birthdate
let displayedItems: [Any] = [Int(kABPersonPhoneProperty), Int(kABPersonEmailProperty), Int(kABPersonBirthdayProperty), Int(kABPersonAddressProperty)]
picker.displayedProperties = displayedItems
// Show the picker
present(picker, animated: true) { _ in }
findSearchBar(picker.view(), mark: "> ")
}

Saurabh Jain
- 1,688
- 14
- 28
-
Thank you for your help, but this code is not working for me, as i am using CNContactPickerViewController, instead of ABAddressbook. So migt be there is change in there view and subviews, as per my code i am unable to satisfy that for loop, its not going inside that loop and its showing 0 elements, when i am printing parent.subviews value. – Richa Gupta Jul 27 '17 at 02:21
-
-
-
-
-
-
As the CNContactPickerViewController is a UIRemoteView you have no access to it – Chris Byatt Feb 28 '19 at 17:47
0
As you can find here the problem seems to be present only if you use the multi-contact selection mode for the CNContactPickerViewController. Implementing the single-contact selection mode you can search for a contact and select it without problems. In order to use the single-contact selection mode make sure you implement in your CNContactPickerDelegate ONLY this method:
func contactPicker(_ picker: CNContactPickerViewController, didSelect contact: CNContact)
and not this method:
func contactPicker(_ picker: CNContactPickerViewController, didSelect contacts: [CNContact])
Implementing both methods the multi-selection mode is used.

Andrea Gorrieri
- 1,704
- 2
- 22
- 36