내 프로젝트에 UISearchBar
과 UITableView
을 추가했습니다. UISearchBar
의 텍스트에 따라 모든 사용자를 필터링하고 tableview에 표시해야합니다. 나는 firebase 문서에서 쿼리를 연구했지만 찾지 못했습니다. 난 부분 문자열에 대한 firebase 쿼리가 필요합니다. 아무도 나를 도울 수 있습니까?모든 사용자를 firebase에 사용자의 전체 이름으로 검색 IOS
답변
나는 당신이 당신의 중포 기지 데이터베이스
- firstName을에
- 이 lastName
을이 있고 중포 기지는 절은,이 문제를 해결하기 위해, 단지 새를 추가 할 위치를 여러 내버려 생각 필드이므로이 형식이됩니다.
- 첫 번째 이름
- 과 lastName
- fullName의
ref.child("users")
.queryOrderedByChild("fullName")
.queryEqualToValue("your full name")
.observeSingleEventOfType(.Value, withBlock: { (snapshot) -> Void in
}
@EdwardAnthony OP에서 질문에 언급 된 부분 문자열 검색을 어떻게 수행 할 수 있습니까? – Jay
@Jay 만약 부분적인 것이라면, 색인을 직접 만들 수 있습니다. 예를 들어 'first1Charater','first2Charater', 'first3Charater' 등의 필드가 있습니다. 그리고'queryOrderedByChild ("first \ (input.characters.count) Character")'를 사용하여 쿼리합니다. –
안녕하세요 희망 .... 내가 당신의 질문을 이해 바랍니다
.....
@IBOutlet var searchBar: UISearchBar!
@IBOutlet var tblview: UITableView!
단계 1 : -make arary
let data =
["xxx", "india, CA", "pakistan", "usa",
"china", "fgsfsgs", "San Diego, CA", "San Antonio, TX",
"Dallas, TX", "Detroit, MI"]
2 단계 - 단지 viewDidLaod() 메소드 현제 글로벌 변수 선언
var filteredData: [String]!
STEP3 : -
override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
tblview.dataSource = self
searchBar.delegate = self
filteredData = data
}
4 단계 : 법 아래에있는 tableView 위임 방법 -use
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell:UITableViewCell = UITableViewCell(style:UITableViewCellStyle.Default, reuseIdentifier:"cell")
cell.textLabel?.text = filteredData[indexPath.row]
return cell
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return filteredData.count
}
5 단계 사용이 ..
func searchBar(searchBar: UISearchBar, textDidChange searchText: String)
{
// When there is no text, filteredData is the same as the original data
if searchText.isEmpty {
filteredData = data //use your array in place od data
} else {
// The user has entered text into the search box
// Use the filter method to iterate over all items in the data array
// For each item, return true if the item should be included and false if the
// item should NOT be included
filteredData = data.filter({(dataItem: String) -> Bool in
// If dataItem matches the searchText, return true to include it
if dataItem.rangeOfString(searchText, options: .CaseInsensitiveSearch) != nil {
return true
} else {
return false
}
})
}
self.tblview.reloadData()
}
답장을 보내 주셔서 감사합니다. 메모리 데이터의이 필터. 하지만 firebase 데이터베이스에서 직접 필터링해야합니다. – sant05
당신이보고 했 이 page?
여기서는 QueryToValue가 유용 할 수 있다고 생각합니다.
당신은 부분 문자열 검색을 수행하고 있습니까? 예 : 사용자가 UISearchBar를 입력 할 때 사용자가 입력 할 때 일치하는 목록이 더 적거나 적은 목록을 업데이트하는 목록에서 자동 채우기를 원하십니까? 또는 전체 문자열을 입력하고 전체 문자열을 검색합니다. – Jay
안녕하세요. 제이 답장을 보내 주셔서 감사합니다. 실제로 부분 문자열 검색을 수행하고 있습니다. – sant05
Firebase는 부분 문자열 검색 (like 또는 유형 쿼리 포함)을 수행하는 방법을 제공하지 않습니다. 그 주의점은 문자열의 첫 번째 부분을 검색하는 경우입니다. 즉, .startingAt 및 .endingAt를 유니 코드 char, \ uf8ff와 함께 사용하는 기술이 있습니다. 또한 Firebase 구조를 설정하여 부분 문자열을 검색 할 수도 있습니다. [Firebase을 사용한 자동 완성] (http : // stackoverflow.com/questions/23506800/autocomplete-with-firebase/23510916 # 23510916) 및 [Firebase에서 검색 중] (http://stackoverflow.com/questions/33867185/searching-in-firebase-without-server-side-code) – Jay