我有一個tableview,它列出了firebase中所有的「地方」。我有一個UISearchController顯然搜索這些「地方」。問題是,當我點擊UISearchController但沒有輸入任何內容,並選擇一個「地點」我得到一個索引超出範圍錯誤。如果我打字或者沒有激活UISearchController,它會很好地工作。只是當它處於活動狀態而不輸入時,當我收到錯誤時。它拋出的錯誤「讓用戶= filteredUsers [indexPath.row]」Swift Firebase UISearchController索引超出範圍
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
super.prepare(for: segue, sender: sender)
if segue.identifier == "BusinessProfiles" {
// gotta check if we're currently searching
if self.searchController.isActive {
if let indexPath = tableView.indexPathForSelectedRow {
let user = filteredUsers[indexPath.row]
let controller = segue.destination as? BusinessProfilesViewController
controller?.otherUser = user
}
} else {
if let indexPath = tableView.indexPathForSelectedRow {
let user = usersArray[indexPath.row]
let controller = segue.destination as? BusinessProfilesViewController
controller?.otherUser = user
}
}
}
}
添加'searchbar.text ==「」'條件,如果我的問題正確 – JuicyFruit
我會在那裏添加? –
感謝您的回答 –