Firebase - Why isnt search for users working in my app? (updating the searchcontroller when user has typed...
up vote
0
down vote
favorite
i have had this issue for a long time. The only way my searchUsers function work is when i put it in ViewDidLoad, and then change the .count to be equal or less than 0 (because its 0 by default).
But as it is right now (how i think it should work), the search dosent work.
What i want it to do is :
- Only start the firebase search for users when the user has typed at least two letters (so it only searches for the users when the user has started typing, and only showing and loading the relevant data).
- Also update the tableview along with filtering the search.
This is my code:
import UIKit
import FirebaseDatabase
import Firebase
import SDWebImage
import ObjectMapper
class FollowUsersTableViewController: UIViewController {
@IBOutlet var tableView: UITableView!
private var viewIsHiddenObserver: NSKeyValueObservation?
let searchController = UISearchController(searchResultsController: nil)
var usersArray = [UserModel]()
var filteredUsers = [UserModel]()
var loggedInUser: User?
//
var databaseRef = Database.database().reference()
//usikker på den koden over
override func viewDidLoad() {
super.viewDidLoad()
//large title
self.title = "Discover"
if #available(iOS 11.0, *) {
self.navigationController?.navigationBar.prefersLargeTitles = true
} else {
// Fallback on earlier versions
}
self.tableView?.delegate = self
self.tableView?.dataSource = self
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
self.searchController.delegate = self;
definesPresentationContext = true
tableView.tableHeaderView = searchController.searchBar
//self.loadProfileData()
//self.searchBar(searchController.searchBar, textDidChange: searchController.searchBar.text)
}
func searchUsers(text: String) {
if text.count >= 2 {
self.usersArray = //clear the array each time
let endingText = text + "u{f8ff}"
databaseRef.child("profile").queryOrdered(byChild: "username")
.queryStarting(atValue: text)
.queryEnding(atValue: endingText)
.observeSingleEvent(of: .value, with: { snapshot in
for child in snapshot.children {
let childSnap = child as! DataSnapshot
print(childSnap)
let userObj = Mapper<UserModel>().map(JSONObject: childSnap.value!)
userObj?.uid = childSnap.key
if childSnap.key != self.loggedInUser?.uid { //ignore this user
self.usersArray.append(userObj!)
}
}
self.tableView.reloadData()
})
}
} //may need an else statement here to clear the array when there is no text
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let dest = segue.destination as! UserProfileViewController
let obj = sender as! UserModel
let dict = ["uid": obj.uid!, "username": obj.username!, "photoURL": obj.photoURL, "bio": obj.bio]
dest.selectedUser = dict as [String : Any]
}
}
// MARK: - tableview methods
extension FollowUsersTableViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return searchController.searchBar.text!.count >= 2 ? filteredUsers.count : 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! FollowTableViewCell
let user = filteredUsers[indexPath.row]
cell.title?.text = user.username
if let url = URL(string: user.photoURL ?? "") {
cell.userImage?.sd_setImage(with: url, placeholderImage: #imageLiteral(resourceName: "user_male"), options: .progressiveDownload, completed: nil)
cell.userImage.sd_setIndicatorStyle(.gray)
cell.userImage.sd_showActivityIndicatorView()
}
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 50
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.performSegue(withIdentifier: "user", sender: self.filteredUsers[indexPath.row])
}
}
// MARK: - search methods
extension FollowUsersTableViewController:UISearchResultsUpdating, UISearchControllerDelegate, UISearchBarDelegate {
func searchBar(_ searchBar: UISearchBar,
textDidChange searchText: String) {
self.searchUsers(text: searchText)
}
func updateSearchResults(for searchController: UISearchController) {
searchController.searchResultsController?.view.isHidden = false
filterContent(searchText: self.searchController.searchBar.text!)
self.tableView.reloadData()
}
func filterContent(searchText:String){
if searchText.count >= 2{
self.filteredUsers = self.usersArray.filter{ user in
return(user.username!.lowercased().contains(searchText.lowercased()))
}
}
}
}
swift firebase uitableview uisearchcontroller
add a comment |
up vote
0
down vote
favorite
i have had this issue for a long time. The only way my searchUsers function work is when i put it in ViewDidLoad, and then change the .count to be equal or less than 0 (because its 0 by default).
But as it is right now (how i think it should work), the search dosent work.
What i want it to do is :
- Only start the firebase search for users when the user has typed at least two letters (so it only searches for the users when the user has started typing, and only showing and loading the relevant data).
- Also update the tableview along with filtering the search.
This is my code:
import UIKit
import FirebaseDatabase
import Firebase
import SDWebImage
import ObjectMapper
class FollowUsersTableViewController: UIViewController {
@IBOutlet var tableView: UITableView!
private var viewIsHiddenObserver: NSKeyValueObservation?
let searchController = UISearchController(searchResultsController: nil)
var usersArray = [UserModel]()
var filteredUsers = [UserModel]()
var loggedInUser: User?
//
var databaseRef = Database.database().reference()
//usikker på den koden over
override func viewDidLoad() {
super.viewDidLoad()
//large title
self.title = "Discover"
if #available(iOS 11.0, *) {
self.navigationController?.navigationBar.prefersLargeTitles = true
} else {
// Fallback on earlier versions
}
self.tableView?.delegate = self
self.tableView?.dataSource = self
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
self.searchController.delegate = self;
definesPresentationContext = true
tableView.tableHeaderView = searchController.searchBar
//self.loadProfileData()
//self.searchBar(searchController.searchBar, textDidChange: searchController.searchBar.text)
}
func searchUsers(text: String) {
if text.count >= 2 {
self.usersArray = //clear the array each time
let endingText = text + "u{f8ff}"
databaseRef.child("profile").queryOrdered(byChild: "username")
.queryStarting(atValue: text)
.queryEnding(atValue: endingText)
.observeSingleEvent(of: .value, with: { snapshot in
for child in snapshot.children {
let childSnap = child as! DataSnapshot
print(childSnap)
let userObj = Mapper<UserModel>().map(JSONObject: childSnap.value!)
userObj?.uid = childSnap.key
if childSnap.key != self.loggedInUser?.uid { //ignore this user
self.usersArray.append(userObj!)
}
}
self.tableView.reloadData()
})
}
} //may need an else statement here to clear the array when there is no text
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let dest = segue.destination as! UserProfileViewController
let obj = sender as! UserModel
let dict = ["uid": obj.uid!, "username": obj.username!, "photoURL": obj.photoURL, "bio": obj.bio]
dest.selectedUser = dict as [String : Any]
}
}
// MARK: - tableview methods
extension FollowUsersTableViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return searchController.searchBar.text!.count >= 2 ? filteredUsers.count : 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! FollowTableViewCell
let user = filteredUsers[indexPath.row]
cell.title?.text = user.username
if let url = URL(string: user.photoURL ?? "") {
cell.userImage?.sd_setImage(with: url, placeholderImage: #imageLiteral(resourceName: "user_male"), options: .progressiveDownload, completed: nil)
cell.userImage.sd_setIndicatorStyle(.gray)
cell.userImage.sd_showActivityIndicatorView()
}
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 50
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.performSegue(withIdentifier: "user", sender: self.filteredUsers[indexPath.row])
}
}
// MARK: - search methods
extension FollowUsersTableViewController:UISearchResultsUpdating, UISearchControllerDelegate, UISearchBarDelegate {
func searchBar(_ searchBar: UISearchBar,
textDidChange searchText: String) {
self.searchUsers(text: searchText)
}
func updateSearchResults(for searchController: UISearchController) {
searchController.searchResultsController?.view.isHidden = false
filterContent(searchText: self.searchController.searchBar.text!)
self.tableView.reloadData()
}
func filterContent(searchText:String){
if searchText.count >= 2{
self.filteredUsers = self.usersArray.filter{ user in
return(user.username!.lowercased().contains(searchText.lowercased()))
}
}
}
}
swift firebase uitableview uisearchcontroller
When you say 'the search doesn't work' what does that mean? Is the searchUsers function called at all? Is Firebase not returning results? Can you please clarify what isn't working and provide some details about where things are going wrong?
– Jay
Nov 11 at 16:16
Hello again Jay. Thanks for your previous help, but im kind of still stuck on this. The function does print the snapshot (so it does actually search), but nothing gets displayed in the tableview.
– Matt Gilbert
Nov 11 at 19:11
Also, for some weird reason , when i search Ma , it only prints the info of user "Makalai", and does not print user "Mattgilbert". I dont know why this happens?
– Matt Gilbert
Nov 11 at 19:17
but my main issue , is that the tableview is empty, even though the info shows up in console
– Matt Gilbert
Nov 11 at 19:18
Do you have a thought on whats wrong my friend?
– Matt Gilbert
Nov 12 at 9:12
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
i have had this issue for a long time. The only way my searchUsers function work is when i put it in ViewDidLoad, and then change the .count to be equal or less than 0 (because its 0 by default).
But as it is right now (how i think it should work), the search dosent work.
What i want it to do is :
- Only start the firebase search for users when the user has typed at least two letters (so it only searches for the users when the user has started typing, and only showing and loading the relevant data).
- Also update the tableview along with filtering the search.
This is my code:
import UIKit
import FirebaseDatabase
import Firebase
import SDWebImage
import ObjectMapper
class FollowUsersTableViewController: UIViewController {
@IBOutlet var tableView: UITableView!
private var viewIsHiddenObserver: NSKeyValueObservation?
let searchController = UISearchController(searchResultsController: nil)
var usersArray = [UserModel]()
var filteredUsers = [UserModel]()
var loggedInUser: User?
//
var databaseRef = Database.database().reference()
//usikker på den koden over
override func viewDidLoad() {
super.viewDidLoad()
//large title
self.title = "Discover"
if #available(iOS 11.0, *) {
self.navigationController?.navigationBar.prefersLargeTitles = true
} else {
// Fallback on earlier versions
}
self.tableView?.delegate = self
self.tableView?.dataSource = self
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
self.searchController.delegate = self;
definesPresentationContext = true
tableView.tableHeaderView = searchController.searchBar
//self.loadProfileData()
//self.searchBar(searchController.searchBar, textDidChange: searchController.searchBar.text)
}
func searchUsers(text: String) {
if text.count >= 2 {
self.usersArray = //clear the array each time
let endingText = text + "u{f8ff}"
databaseRef.child("profile").queryOrdered(byChild: "username")
.queryStarting(atValue: text)
.queryEnding(atValue: endingText)
.observeSingleEvent(of: .value, with: { snapshot in
for child in snapshot.children {
let childSnap = child as! DataSnapshot
print(childSnap)
let userObj = Mapper<UserModel>().map(JSONObject: childSnap.value!)
userObj?.uid = childSnap.key
if childSnap.key != self.loggedInUser?.uid { //ignore this user
self.usersArray.append(userObj!)
}
}
self.tableView.reloadData()
})
}
} //may need an else statement here to clear the array when there is no text
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let dest = segue.destination as! UserProfileViewController
let obj = sender as! UserModel
let dict = ["uid": obj.uid!, "username": obj.username!, "photoURL": obj.photoURL, "bio": obj.bio]
dest.selectedUser = dict as [String : Any]
}
}
// MARK: - tableview methods
extension FollowUsersTableViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return searchController.searchBar.text!.count >= 2 ? filteredUsers.count : 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! FollowTableViewCell
let user = filteredUsers[indexPath.row]
cell.title?.text = user.username
if let url = URL(string: user.photoURL ?? "") {
cell.userImage?.sd_setImage(with: url, placeholderImage: #imageLiteral(resourceName: "user_male"), options: .progressiveDownload, completed: nil)
cell.userImage.sd_setIndicatorStyle(.gray)
cell.userImage.sd_showActivityIndicatorView()
}
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 50
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.performSegue(withIdentifier: "user", sender: self.filteredUsers[indexPath.row])
}
}
// MARK: - search methods
extension FollowUsersTableViewController:UISearchResultsUpdating, UISearchControllerDelegate, UISearchBarDelegate {
func searchBar(_ searchBar: UISearchBar,
textDidChange searchText: String) {
self.searchUsers(text: searchText)
}
func updateSearchResults(for searchController: UISearchController) {
searchController.searchResultsController?.view.isHidden = false
filterContent(searchText: self.searchController.searchBar.text!)
self.tableView.reloadData()
}
func filterContent(searchText:String){
if searchText.count >= 2{
self.filteredUsers = self.usersArray.filter{ user in
return(user.username!.lowercased().contains(searchText.lowercased()))
}
}
}
}
swift firebase uitableview uisearchcontroller
i have had this issue for a long time. The only way my searchUsers function work is when i put it in ViewDidLoad, and then change the .count to be equal or less than 0 (because its 0 by default).
But as it is right now (how i think it should work), the search dosent work.
What i want it to do is :
- Only start the firebase search for users when the user has typed at least two letters (so it only searches for the users when the user has started typing, and only showing and loading the relevant data).
- Also update the tableview along with filtering the search.
This is my code:
import UIKit
import FirebaseDatabase
import Firebase
import SDWebImage
import ObjectMapper
class FollowUsersTableViewController: UIViewController {
@IBOutlet var tableView: UITableView!
private var viewIsHiddenObserver: NSKeyValueObservation?
let searchController = UISearchController(searchResultsController: nil)
var usersArray = [UserModel]()
var filteredUsers = [UserModel]()
var loggedInUser: User?
//
var databaseRef = Database.database().reference()
//usikker på den koden over
override func viewDidLoad() {
super.viewDidLoad()
//large title
self.title = "Discover"
if #available(iOS 11.0, *) {
self.navigationController?.navigationBar.prefersLargeTitles = true
} else {
// Fallback on earlier versions
}
self.tableView?.delegate = self
self.tableView?.dataSource = self
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
self.searchController.delegate = self;
definesPresentationContext = true
tableView.tableHeaderView = searchController.searchBar
//self.loadProfileData()
//self.searchBar(searchController.searchBar, textDidChange: searchController.searchBar.text)
}
func searchUsers(text: String) {
if text.count >= 2 {
self.usersArray = //clear the array each time
let endingText = text + "u{f8ff}"
databaseRef.child("profile").queryOrdered(byChild: "username")
.queryStarting(atValue: text)
.queryEnding(atValue: endingText)
.observeSingleEvent(of: .value, with: { snapshot in
for child in snapshot.children {
let childSnap = child as! DataSnapshot
print(childSnap)
let userObj = Mapper<UserModel>().map(JSONObject: childSnap.value!)
userObj?.uid = childSnap.key
if childSnap.key != self.loggedInUser?.uid { //ignore this user
self.usersArray.append(userObj!)
}
}
self.tableView.reloadData()
})
}
} //may need an else statement here to clear the array when there is no text
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let dest = segue.destination as! UserProfileViewController
let obj = sender as! UserModel
let dict = ["uid": obj.uid!, "username": obj.username!, "photoURL": obj.photoURL, "bio": obj.bio]
dest.selectedUser = dict as [String : Any]
}
}
// MARK: - tableview methods
extension FollowUsersTableViewController: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return searchController.searchBar.text!.count >= 2 ? filteredUsers.count : 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! FollowTableViewCell
let user = filteredUsers[indexPath.row]
cell.title?.text = user.username
if let url = URL(string: user.photoURL ?? "") {
cell.userImage?.sd_setImage(with: url, placeholderImage: #imageLiteral(resourceName: "user_male"), options: .progressiveDownload, completed: nil)
cell.userImage.sd_setIndicatorStyle(.gray)
cell.userImage.sd_showActivityIndicatorView()
}
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 50
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.performSegue(withIdentifier: "user", sender: self.filteredUsers[indexPath.row])
}
}
// MARK: - search methods
extension FollowUsersTableViewController:UISearchResultsUpdating, UISearchControllerDelegate, UISearchBarDelegate {
func searchBar(_ searchBar: UISearchBar,
textDidChange searchText: String) {
self.searchUsers(text: searchText)
}
func updateSearchResults(for searchController: UISearchController) {
searchController.searchResultsController?.view.isHidden = false
filterContent(searchText: self.searchController.searchBar.text!)
self.tableView.reloadData()
}
func filterContent(searchText:String){
if searchText.count >= 2{
self.filteredUsers = self.usersArray.filter{ user in
return(user.username!.lowercased().contains(searchText.lowercased()))
}
}
}
}
swift firebase uitableview uisearchcontroller
swift firebase uitableview uisearchcontroller
edited Nov 12 at 21:23
Jay
17.9k42848
17.9k42848
asked Nov 10 at 22:09
Matt Gilbert
168
168
When you say 'the search doesn't work' what does that mean? Is the searchUsers function called at all? Is Firebase not returning results? Can you please clarify what isn't working and provide some details about where things are going wrong?
– Jay
Nov 11 at 16:16
Hello again Jay. Thanks for your previous help, but im kind of still stuck on this. The function does print the snapshot (so it does actually search), but nothing gets displayed in the tableview.
– Matt Gilbert
Nov 11 at 19:11
Also, for some weird reason , when i search Ma , it only prints the info of user "Makalai", and does not print user "Mattgilbert". I dont know why this happens?
– Matt Gilbert
Nov 11 at 19:17
but my main issue , is that the tableview is empty, even though the info shows up in console
– Matt Gilbert
Nov 11 at 19:18
Do you have a thought on whats wrong my friend?
– Matt Gilbert
Nov 12 at 9:12
add a comment |
When you say 'the search doesn't work' what does that mean? Is the searchUsers function called at all? Is Firebase not returning results? Can you please clarify what isn't working and provide some details about where things are going wrong?
– Jay
Nov 11 at 16:16
Hello again Jay. Thanks for your previous help, but im kind of still stuck on this. The function does print the snapshot (so it does actually search), but nothing gets displayed in the tableview.
– Matt Gilbert
Nov 11 at 19:11
Also, for some weird reason , when i search Ma , it only prints the info of user "Makalai", and does not print user "Mattgilbert". I dont know why this happens?
– Matt Gilbert
Nov 11 at 19:17
but my main issue , is that the tableview is empty, even though the info shows up in console
– Matt Gilbert
Nov 11 at 19:18
Do you have a thought on whats wrong my friend?
– Matt Gilbert
Nov 12 at 9:12
When you say 'the search doesn't work' what does that mean? Is the searchUsers function called at all? Is Firebase not returning results? Can you please clarify what isn't working and provide some details about where things are going wrong?
– Jay
Nov 11 at 16:16
When you say 'the search doesn't work' what does that mean? Is the searchUsers function called at all? Is Firebase not returning results? Can you please clarify what isn't working and provide some details about where things are going wrong?
– Jay
Nov 11 at 16:16
Hello again Jay. Thanks for your previous help, but im kind of still stuck on this. The function does print the snapshot (so it does actually search), but nothing gets displayed in the tableview.
– Matt Gilbert
Nov 11 at 19:11
Hello again Jay. Thanks for your previous help, but im kind of still stuck on this. The function does print the snapshot (so it does actually search), but nothing gets displayed in the tableview.
– Matt Gilbert
Nov 11 at 19:11
Also, for some weird reason , when i search Ma , it only prints the info of user "Makalai", and does not print user "Mattgilbert". I dont know why this happens?
– Matt Gilbert
Nov 11 at 19:17
Also, for some weird reason , when i search Ma , it only prints the info of user "Makalai", and does not print user "Mattgilbert". I dont know why this happens?
– Matt Gilbert
Nov 11 at 19:17
but my main issue , is that the tableview is empty, even though the info shows up in console
– Matt Gilbert
Nov 11 at 19:18
but my main issue , is that the tableview is empty, even though the info shows up in console
– Matt Gilbert
Nov 11 at 19:18
Do you have a thought on whats wrong my friend?
– Matt Gilbert
Nov 12 at 9:12
Do you have a thought on whats wrong my friend?
– Matt Gilbert
Nov 12 at 9:12
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
You need to set
searchController.searchBar.delegate = self
You conform to UISearchResultsUpdating
and implement updateSearchResults
but it doesn't call func searchUsers(text: String)
and conform to UISearchControllerDelegate
that has no relation to the search look to it's methods Here
Where should i set it? i think ill set it as self
– Matt Gilbert
Nov 10 at 22:35
viewDidLoad ..............
– Sh_Khan
Nov 10 at 22:35
It still dosent work?..
– Matt Gilbert
Nov 11 at 10:03
try to move self.searchUsers(text: searchText) to updateSearchResults
– Sh_Khan
Nov 11 at 10:09
Still dosent work , when i addself.searchUsers(text: self.searchController.searchBar.text!)
tofunc updateSearchResults
– Matt Gilbert
Nov 11 at 13:29
|
show 1 more comment
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You need to set
searchController.searchBar.delegate = self
You conform to UISearchResultsUpdating
and implement updateSearchResults
but it doesn't call func searchUsers(text: String)
and conform to UISearchControllerDelegate
that has no relation to the search look to it's methods Here
Where should i set it? i think ill set it as self
– Matt Gilbert
Nov 10 at 22:35
viewDidLoad ..............
– Sh_Khan
Nov 10 at 22:35
It still dosent work?..
– Matt Gilbert
Nov 11 at 10:03
try to move self.searchUsers(text: searchText) to updateSearchResults
– Sh_Khan
Nov 11 at 10:09
Still dosent work , when i addself.searchUsers(text: self.searchController.searchBar.text!)
tofunc updateSearchResults
– Matt Gilbert
Nov 11 at 13:29
|
show 1 more comment
up vote
0
down vote
You need to set
searchController.searchBar.delegate = self
You conform to UISearchResultsUpdating
and implement updateSearchResults
but it doesn't call func searchUsers(text: String)
and conform to UISearchControllerDelegate
that has no relation to the search look to it's methods Here
Where should i set it? i think ill set it as self
– Matt Gilbert
Nov 10 at 22:35
viewDidLoad ..............
– Sh_Khan
Nov 10 at 22:35
It still dosent work?..
– Matt Gilbert
Nov 11 at 10:03
try to move self.searchUsers(text: searchText) to updateSearchResults
– Sh_Khan
Nov 11 at 10:09
Still dosent work , when i addself.searchUsers(text: self.searchController.searchBar.text!)
tofunc updateSearchResults
– Matt Gilbert
Nov 11 at 13:29
|
show 1 more comment
up vote
0
down vote
up vote
0
down vote
You need to set
searchController.searchBar.delegate = self
You conform to UISearchResultsUpdating
and implement updateSearchResults
but it doesn't call func searchUsers(text: String)
and conform to UISearchControllerDelegate
that has no relation to the search look to it's methods Here
You need to set
searchController.searchBar.delegate = self
You conform to UISearchResultsUpdating
and implement updateSearchResults
but it doesn't call func searchUsers(text: String)
and conform to UISearchControllerDelegate
that has no relation to the search look to it's methods Here
edited Nov 10 at 22:36
answered Nov 10 at 22:33
Sh_Khan
33.9k41125
33.9k41125
Where should i set it? i think ill set it as self
– Matt Gilbert
Nov 10 at 22:35
viewDidLoad ..............
– Sh_Khan
Nov 10 at 22:35
It still dosent work?..
– Matt Gilbert
Nov 11 at 10:03
try to move self.searchUsers(text: searchText) to updateSearchResults
– Sh_Khan
Nov 11 at 10:09
Still dosent work , when i addself.searchUsers(text: self.searchController.searchBar.text!)
tofunc updateSearchResults
– Matt Gilbert
Nov 11 at 13:29
|
show 1 more comment
Where should i set it? i think ill set it as self
– Matt Gilbert
Nov 10 at 22:35
viewDidLoad ..............
– Sh_Khan
Nov 10 at 22:35
It still dosent work?..
– Matt Gilbert
Nov 11 at 10:03
try to move self.searchUsers(text: searchText) to updateSearchResults
– Sh_Khan
Nov 11 at 10:09
Still dosent work , when i addself.searchUsers(text: self.searchController.searchBar.text!)
tofunc updateSearchResults
– Matt Gilbert
Nov 11 at 13:29
Where should i set it? i think ill set it as self
– Matt Gilbert
Nov 10 at 22:35
Where should i set it? i think ill set it as self
– Matt Gilbert
Nov 10 at 22:35
viewDidLoad ..............
– Sh_Khan
Nov 10 at 22:35
viewDidLoad ..............
– Sh_Khan
Nov 10 at 22:35
It still dosent work?..
– Matt Gilbert
Nov 11 at 10:03
It still dosent work?..
– Matt Gilbert
Nov 11 at 10:03
try to move self.searchUsers(text: searchText) to updateSearchResults
– Sh_Khan
Nov 11 at 10:09
try to move self.searchUsers(text: searchText) to updateSearchResults
– Sh_Khan
Nov 11 at 10:09
Still dosent work , when i add
self.searchUsers(text: self.searchController.searchBar.text!)
to func updateSearchResults
– Matt Gilbert
Nov 11 at 13:29
Still dosent work , when i add
self.searchUsers(text: self.searchController.searchBar.text!)
to func updateSearchResults
– Matt Gilbert
Nov 11 at 13:29
|
show 1 more comment
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53243916%2ffirebase-why-isnt-search-for-users-working-in-my-app-updating-the-searchcont%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
When you say 'the search doesn't work' what does that mean? Is the searchUsers function called at all? Is Firebase not returning results? Can you please clarify what isn't working and provide some details about where things are going wrong?
– Jay
Nov 11 at 16:16
Hello again Jay. Thanks for your previous help, but im kind of still stuck on this. The function does print the snapshot (so it does actually search), but nothing gets displayed in the tableview.
– Matt Gilbert
Nov 11 at 19:11
Also, for some weird reason , when i search Ma , it only prints the info of user "Makalai", and does not print user "Mattgilbert". I dont know why this happens?
– Matt Gilbert
Nov 11 at 19:17
but my main issue , is that the tableview is empty, even though the info shows up in console
– Matt Gilbert
Nov 11 at 19:18
Do you have a thought on whats wrong my friend?
– Matt Gilbert
Nov 12 at 9:12