我有一个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
我会在那里添加? –
感谢您的回答 –