我有一个UITableView和UISearchBar。我在tableview中显示了一些coredata值,例如员工姓名。如果我选择特定员工姓名上的行,员工的详细信息应该显示在另一个视图控制器中,我使用这个“覆盖功能准备(对于segue:UIStoryboardSegue,发件人:任何?)”segue方法。
问题是,每当我使用搜索栏过滤员工姓名,并使用在表格视图上点击过滤后的员工姓名时,不会调用“覆盖功能准备(对于segue:UIStoryboardSegue,发件人:任何?)”。但是如果没有搜索,我可以导航到具有所选员工的详细视图控制器。但是如果使用搜索栏过滤名称,我无法实现对员工细节的segue导航。 请告诉我在搜索结果之后没有导航的原因或建议解决方案。
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let object : Any
if(searchActive){
let indexPath = self.searchDisplayController?.searchResultsTableView.indexPathForSelectedRow
object = self.filteredEmployees[(indexPath?.row)!]
}
else{
let indexPath = tableView.indexPathForSelectedRow
object = self.employees[(indexPath?.row)!]
}
let controller = (segue.destination as! UINavigationController).topViewController as! DetailViewController
//controller.detailItem = object
controller.navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem
controller.navigationItem.leftItemsSupplementBackButton = true
controller.employees = object as! EmployeeDetails
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCell(withIdentifier: "Cell")
if cell == nil {
cell = UITableViewCell(style: UITableViewCellStyle.value1, reuseIdentifier: "Cell")
}
cell?.textLabel!.numberOfLines = 0
cell?.textLabel!.lineBreakMode = .byWordWrapping
cell?.textLabel!.font = UIFont.systemFont(ofSize: 14.0)
if(searchActive){
var filter: EmployeeDetails? = nil
filter = self.filteredEmployees[indexPath.row]
cell?.textLabel?.text = String(format:"%@ %@", (filter?.firstName!)!, (filter?.lastName!)!)
cell?.detailTextLabel!.text = String(format:"%@", (filter?.title!)!)
} else
{
var employee : EmployeeDetails? = nil
employee = self.employees[indexPath.row]
cell?.textLabel?.text = String(format:"%@ %@", (employee?.firstName!)!, (employee?.lastName!)!)
cell?.detailTextLabel!.text = String(format:"%@", (employee?.title!)!)
}
return cell!
}