我目前正在使用“联系人”应用程序,只是为了测试某些功能,而我一直受搜索栏困扰。我无法在首页中的所有联系人之间进行搜索。Swift 4.2和Xcode 10
class ContactsViewController: UITableViewController, CNContactViewControllerDelegate, UISearchBarDelegate {
// Outlet for Search Bar
@IBOutlet weak var searchBar: UISearchBar!
Run Code Online (Sandbox Code Playgroud)
这是我在IBOutlet上的代表的定义
然后我要在首页显示联系人
/ * Show Contacts *
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if contactList != nil {
return contactList.count
}
return 0
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "contactCell", for: indexPath)
let contact: CNContact!
contact = contactList[indexPath.row]
cell.textLabel?.text = "\(contact.givenName) \(contact.familyName)"
return cell
}
override …Run Code Online (Sandbox Code Playgroud)