How to implement Search with UISearchBar in Parse's PFQueryTableViewController,So user can search though tableview Text content.
So here is my problem so far : No result in the search bar and no crash !
Everything works well but after tapping search button adding text no result!
What seems to be the problem?
There aren't many tutorial about how to make it?
I've tried and this is my code.
ViewController
Class PFQueryTableViewController,UISearchBarDelegate
override func queryForTable() -> PFQuery {
var query = PFQuery(className: "Event")
if searchBar.text != "" {
query.whereKey("searchText", containsString: searchBar.text!.lowercaseString)
}
query.cachePolicy = PFCachePolicy.CacheThenNetwork
query.orderByAscending("createdAt")
return query
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject?) -> PFTableViewCell? {
var cell = tableView.dequeueReusableCellWithIdentifier("EventCell") as! EventTableCell!
if cell == nil {
cell = EventTableCell(style: UITableViewCellStyle.Default, reuseIdentifier: "EventCell")
}
if let eventTitle = object!["eventTitle"] as? String {
cell?.titleLabel?.text = eventTitle
}
}
///UPDATE UISearchBar Code.
func searchBarTextDidEndEditing(searchBar: UISearchBar) {
// Dismiss the keyboard
searchBar.resignFirstResponder()
// Force reload of table data
self.loadObjects()
}
func searchBarSearchButtonClicked(searchBar: UISearchBar) {
// Dismiss the keyboard
searchBar.resignFirstResponder()
// Force reload of table data
self.loadObjects()
}
func searchBarCancelButtonClicked(searchBar: UISearchBar) {
// Clear any search criteria
searchBar.text = ""
// Dismiss the keyboard
searchBar.resignFirstResponder()
// Force reload of table data
self.loadObjects()
}
override func viewDidAppear(animated: Bool) {
// Refresh the table to ensure any data changes are displayed
tableView.reloadData()
// Delegate the search bar to this table view class
searchBar.delegate = self
}