Search in TableView Swift 3 - не работате segue при нажатии на ячейку. Причина как я понимаю кроется в том, что результат отдается, в resultController. Но чтобы я не делал segue не работает. Направьте ПОЖЖЖ!
class TableViewController: UITableViewController, UISearchResultsUpdating {
var searchController : UISearchController!
var resultController = UITableViewController()
var arFiltLet = [String]()
var arLetter = ["Privet","test","А","Б","В","Г","Д","Е","Ж","З","И","Й","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х","Ц","Ч","Ш","Щ","Э","Ю","Я"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.searchController = UISearchController(searchResultsController: self.resultController)
self.tableView.tableHeaderView = self.searchController.searchBar
self.searchController.searchResultsUpdater = self
self.resultController.tableView.dataSource = self
self.resultController.tableView.delegate = self
definesPresentationContext = true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func updateSearchResults(for searchController: UISearchController) {
self.arFiltLet = self.arLetter.filter{(lett : String) -> Bool in
if lett.lowercased().contains(self.searchController.searchBar.text!.lowercased()){
return true
}else{
return false
}
}
self.resultController.tableView.reloadData()
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if tableView == self.tableView {
return self.arLetter.count
}else{
return self.arFiltLet.count
}
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
if tableView == self.tableView{
cell.textLabel?.text = self.arLetter[indexPath.row]
}else{
cell.textLabel?.text = self.arFiltLet[indexPath.row]
}
return cell
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "segueTableToalpavitTable" && searchController.isActive {
if let indexPath = self.resultController.tableView.indexPathForSelectedRow {
let destanation = segue.destination as! AlphavitTableController
destanation.letter = arFiltLet[(indexPath.row)]
} else if let indexPath = self.tableView.indexPathForSelectedRow {
let destanation = segue.destination as! AlphavitTableController
destanation.letter = arLetter[(indexPath.row)]
}
}
if segue.identifier == "segueTableToalpavitTable" {
if let indexPath = self.tableView.indexPathForSelectedRow {
let destanation = segue.destination as! AlphavitTableController
destanation.letter = arLetter[(indexPath.row)]
}
}
}
}