【发布时间】:2017-08-21 22:00:22
【问题描述】:
我有一个表格视图,列出了我在 firebase 中的所有“地点”。我有一个 UISearchController 显然可以搜索这些“地方”。问题是当我只是点击 UISearchController 但不输入任何内容并选择“位置”时,我得到一个索引超出范围错误。如果我正在输入或没有激活 UISearchController,它会很好。就在它处于活动状态且不输入时,我收到错误消息。它在“让用户=过滤用户[indexPath.row]”上引发错误
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 == ""条件,如果我正确地解决了您的问题 -
我应该在哪里添加?
-
感谢您的回答
标签: swift firebase search segue uisearchcontroller