快速搜索附近的用户

时间:2017-04-10 12:42:07

标签: ios swift uisearchbar uisearchbardelegate

我添加了一个"显示附近的朋友"搜索屏幕的按钮但不起作用。 如果我搜索"某事"然后按下"显示附近的朋友"搜索查询被删除,没有任何反应。

这是代码:

// MARK: - QUERY USERS
func queryUsers(text: String, location: Bool) {
    showHUD(message: "Searching...")
    let keywords = text.lowercased().components(separatedBy: " ")

    let query = PFUser.query()!
    //if location == false {
        query.whereKey(USER_FULLNAME_LOWERCASE, containedIn: keywords)
    //}
    // Search nearby 100 Km
    if location == true {
        if currLocation != nil {
            let gp = PFGeoPoint(latitude: currLocation!.coordinate.latitude, longitude: currLocation!.coordinate.longitude)
            query.whereKey(USER_LOCATION, nearGeoPoint: gp, withinKilometers: 100)
        }
    }

    query.findObjectsInBackground(block: { (users, error) in
        if error == nil {
            self.foundFriendsArray = users!
            self.searchTableView.reloadData()
            self.hideHUD()

        } else {
            self.simpleAlert(mess: "\(error!.localizedDescription)")
            self.hideHUD()
        }})
}
// MARK: - SERACH BAR DELEGATES
func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
    if searchBar.text == "" {
        simpleAlert(mess: "You must type a name to search for friends")
    } else {
        queryUsers(text: searchBar.text!, location: true)
        searchBar.showsCancelButton = false
        searchBar.resignFirstResponder()
    }
}

func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
    searchBar.showsCancelButton = true
}

func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
    searchBar.showsCancelButton = false
    searchBar.resignFirstResponder()
}





// MARK: - SEARCH NEARBY FRIENDS BUTTON
@IBAction func searchNearbyButt(_ sender: Any) {
    searchBar.text = ""
    searchBar.showsCancelButton = false
    searchBar.resignFirstResponder()

    // Call query
    queryUsers(text: searchBar.text!, location: true)
}

我做错了什么?

0 个答案:

没有答案