在swift中实现UISearchBar的麻烦?

时间:2015-12-08 04:48:06

标签: ios swift uisearchbar

所以我正在使用Parse搞乱用户查询。我在UIViewController中有一个表视图作为我的数据源,我正在使用它的扩展名

extension addFriend: UISearchBarDelegate, UISearchDisplayDelegate {

    func searchBarSearchButtonClicked(searchBar: UISearchBar) {
        print("worked")
    }

    func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
        print("editing")
        searchBar.setShowsCancelButton(true, animated: true)
        state = .SearchState
    }  

    func searchBarCancelButtonClicked(searchBar: UISearchBar) {
        searchBar.resignFirstResponder()
        searchBar.text = ""
        searchBar.setShowsCancelButton(false, animated: true)
        state = .DefaultState
    }

    func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
        Reachability.searchUsers(searchText, block: updateList)
    }

}

专门为我的搜索栏声明为

@IBOutlet weak var searchBar: UISearchBar!

可达性是一个公共类,具有我的查询功能,例如: searchUsers()。

我正在使用此处描述的模型 https://www.makeschool.com/tutorials/build-a-photo-sharing-app-part-2/friend-search-follow 但由于某种原因,搜索栏无法正常工作。打印语句用于验证这一事实,并且我尝试在类声明中使用搜索栏代表并在类中键入搜索栏功能,因为我在尝试此操作之前不久写了类似的代码。它不起作用,我无法弄清楚原因。我以前做过这个,它工作得很好。我是快速编程的新手,有什么我想念的吗?我会感谢任何帮助或推动正确的方向。提前谢谢!

0 个答案:

没有答案