Firebase - Why isnt search for users working in my app? (updating the searchcontroller when user has typed two letters)
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 + "uf8ff"
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 |
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 + "uf8ff"
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 '18 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 '18 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 '18 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 '18 at 19:18
Do you have a thought on whats wrong my friend?
– Matt Gilbert
Nov 12 '18 at 9:12
add a comment |
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 + "uf8ff"
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 + "uf8ff"
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 '18 at 21:23
Jay
18.7k42949
18.7k42949
asked Nov 10 '18 at 22:09
Matt GilbertMatt Gilbert
188
188
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 '18 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 '18 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 '18 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 '18 at 19:18
Do you have a thought on whats wrong my friend?
– Matt Gilbert
Nov 12 '18 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 '18 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 '18 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 '18 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 '18 at 19:18
Do you have a thought on whats wrong my friend?
– Matt Gilbert
Nov 12 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 at 19:18
Do you have a thought on whats wrong my friend?
– Matt Gilbert
Nov 12 '18 at 9:12
Do you have a thought on whats wrong my friend?
– Matt Gilbert
Nov 12 '18 at 9:12
add a comment |
1 Answer
1
active
oldest
votes
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 '18 at 22:35
viewDidLoad ..............
– Sh_Khan
Nov 10 '18 at 22:35
It still dosent work?..
– Matt Gilbert
Nov 11 '18 at 10:03
try to move self.searchUsers(text: searchText) to updateSearchResults
– Sh_Khan
Nov 11 '18 at 10:09
Still dosent work , when i addself.searchUsers(text: self.searchController.searchBar.text!)
tofunc updateSearchResults
– Matt Gilbert
Nov 11 '18 at 13:29
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 '18 at 22:35
viewDidLoad ..............
– Sh_Khan
Nov 10 '18 at 22:35
It still dosent work?..
– Matt Gilbert
Nov 11 '18 at 10:03
try to move self.searchUsers(text: searchText) to updateSearchResults
– Sh_Khan
Nov 11 '18 at 10:09
Still dosent work , when i addself.searchUsers(text: self.searchController.searchBar.text!)
tofunc updateSearchResults
– Matt Gilbert
Nov 11 '18 at 13:29
|
show 1 more comment
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 '18 at 22:35
viewDidLoad ..............
– Sh_Khan
Nov 10 '18 at 22:35
It still dosent work?..
– Matt Gilbert
Nov 11 '18 at 10:03
try to move self.searchUsers(text: searchText) to updateSearchResults
– Sh_Khan
Nov 11 '18 at 10:09
Still dosent work , when i addself.searchUsers(text: self.searchController.searchBar.text!)
tofunc updateSearchResults
– Matt Gilbert
Nov 11 '18 at 13:29
|
show 1 more comment
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 '18 at 22:36
answered Nov 10 '18 at 22:33
Sh_KhanSh_Khan
40.6k51125
40.6k51125
Where should i set it? i think ill set it as self
– Matt Gilbert
Nov 10 '18 at 22:35
viewDidLoad ..............
– Sh_Khan
Nov 10 '18 at 22:35
It still dosent work?..
– Matt Gilbert
Nov 11 '18 at 10:03
try to move self.searchUsers(text: searchText) to updateSearchResults
– Sh_Khan
Nov 11 '18 at 10:09
Still dosent work , when i addself.searchUsers(text: self.searchController.searchBar.text!)
tofunc updateSearchResults
– Matt Gilbert
Nov 11 '18 at 13:29
|
show 1 more comment
Where should i set it? i think ill set it as self
– Matt Gilbert
Nov 10 '18 at 22:35
viewDidLoad ..............
– Sh_Khan
Nov 10 '18 at 22:35
It still dosent work?..
– Matt Gilbert
Nov 11 '18 at 10:03
try to move self.searchUsers(text: searchText) to updateSearchResults
– Sh_Khan
Nov 11 '18 at 10:09
Still dosent work , when i addself.searchUsers(text: self.searchController.searchBar.text!)
tofunc updateSearchResults
– Matt Gilbert
Nov 11 '18 at 13:29
Where should i set it? i think ill set it as self
– Matt Gilbert
Nov 10 '18 at 22:35
Where should i set it? i think ill set it as self
– Matt Gilbert
Nov 10 '18 at 22:35
viewDidLoad ..............
– Sh_Khan
Nov 10 '18 at 22:35
viewDidLoad ..............
– Sh_Khan
Nov 10 '18 at 22:35
It still dosent work?..
– Matt Gilbert
Nov 11 '18 at 10:03
It still dosent work?..
– Matt Gilbert
Nov 11 '18 at 10:03
try to move self.searchUsers(text: searchText) to updateSearchResults
– Sh_Khan
Nov 11 '18 at 10:09
try to move self.searchUsers(text: searchText) to updateSearchResults
– Sh_Khan
Nov 11 '18 at 10:09
Still dosent work , when i add
self.searchUsers(text: self.searchController.searchBar.text!)
to func updateSearchResults
– Matt Gilbert
Nov 11 '18 at 13:29
Still dosent work , when i add
self.searchUsers(text: self.searchController.searchBar.text!)
to func updateSearchResults
– Matt Gilbert
Nov 11 '18 at 13:29
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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 '18 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 '18 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 '18 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 '18 at 19:18
Do you have a thought on whats wrong my friend?
– Matt Gilbert
Nov 12 '18 at 9:12