Answer the question
In order to leave comments, you need to log in
Search in TableView Swift 3 - Segue doesn't work when cell is clicked?
Search in TableView Swift 3 - Segue doesn't work when cell is clicked. The reason, as I understand it, lies in the fact that the result is given in the resultController. But whatever I do segue doesn't work. Send POZZZHZH!
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)]
}
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question