사람들이 게시물을 게시 할 수있는 간단한 응용 프로그램이있어서 사람들이 게시물을 검색 할 수 있지만 검색 할 수 있도록 검색 바를 만들었습니다. title
의 게시물 또는 location
의 게시물 또는 제목과 위치의 검색을 동시에 수행 할 수 있습니다. 내 검색은 내 firebase 데이터베이스를 통해 검색하지만 나는 title
또는 location
중 하나만 검색하도록 지정할 수 있습니다. 그것은 동시에 boths 키를 검색 그래서 난 내 코드를 필터링 및 검색이신속한 여러 키 검색 4
func filterContent(searchText:String) {
self.filteredUsers = self.userArray.filter{user in
// let title = user!["title"] as? String
let adress = user!["adress"] as? String
// return(title?.lowercased().contains(searchText.lowercased()))!
return(adress?.lowercased().contains(searchText.lowercased()))!
}
tableView.reloadData()
}
과 같은
분명히 당신은 내가 오직 하나의 반환 할 수 있음을 알 수 그것을 만들 수있는 약간의 문제가 수색은 당신이 내가이 두 가지를 모두 돌려 줄 수있는 어떤 방법으로 알고 있니?
나는이
func filterContent(searchText:String) {
self.filteredUsers = self.userArray.filter{user in
let title = user!["title"] as? String
let adress = user!["adress"] as? String
return(adress?.lowercased().contains(searchText.lowercased()))! && (title?.lowercased().contains(searchText.lowercased()))!
}
tableView.reloadData()
}
을 시도했지만 코드는 예를 들어 제목과 주소를 모두가 "사과"다음이 작동 이름을 지정하면 검색 기능이 작동 할 수 있지만 title
경우 "사과 이름 "adress
은"orange "라는 이름이고"apple "또는"orange "를 검색 할 때는 &&
이 bool로 작동하므로 아무 것도 표시되지 않으며 title
과 location
의 키가 같은 경우에만 작동합니다. 그러므로 나는
func filterContent(searchText:String) {
self.filteredUsers = self.userArray.filter{ user in
let title = user!["title"] as? String
let address = user!["adress"] as? String
return title.localizedCaseInsensitiveContains(searchText) == true || address.localizedCaseInsensitiveContains(searchText) == true
}
tableView.reloadData()
}
나는 생각 .. 원점에서 여전히이고 내가 가능성이 검색 필터가 좀 더 가까이 아래에 넣어 모두
title
및
address