小编tra*_*scu的帖子

Swift 4.2使用Contacts Framework使用搜索栏搜索联系人

我目前正在使用“联系人”应用程序,只是为了测试某些功能,而我一直受搜索栏困扰。我无法在首页中的所有联系人之间进行搜索。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)

contacts uisearchbar ios swift

2
推荐指数
1
解决办法
1433
查看次数

标签 统计

contacts ×1

ios ×1

swift ×1

uisearchbar ×1