I am implementing search controller programatically on navigation bar it is working fine and showing result, if I can select the tableview cell(did select method) segue is working fine . when I select the searched result it is not segue to next view controller. It is showing same view controller and tableview is reloading with data. I have show once click search result segue to next view controller
image enter image description here
var modeldata = [ModelData]()
var FilerData = [ModelData]()
override func viewDidLoad() {
super.viewDidLoad()
self.searchcontroller = UISearchController(searchResultsController: nil)
self.searchcontroller.delegate = self
self.searchcontroller.searchBar.delegate = self
self.searchcontroller.hidesNavigationBarDuringPresentation = false
self.searchcontroller.dimsBackgroundDuringPresentation = true
self.navigationItem.titleView = searchcontroller.searchBar
self.definesPresentationContext = true
self.searchcontroller.searchResultsUpdater = self
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return modeldata.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomTableViewCell
let row = indexPath.row
let values = modeldata[row] as ModelData
cell.NameLabel.text = values.name
return cell
}
func updateSearchResults(for searchController: UISearchController) {
let searchToSearch = searchController.searchBar.text
if(searchToSearch == "")
{
modeldata = self.FilerData
}
else{
modeldata.removeAll()
let itemsarray = self.FilerData
var ListArray = [String]()
for ListItems in itemsarray {
ListArray.append(ListItems.name!)
if(ListItems.name?.range(of: searchToSearch!, options: .caseInsensitive) != nil)
{
self.modeldata.append(ListItems)
}
}
}
self.TableView.reloadData()
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "next", sender:indexPath.row )
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let selectrow = sender as? Int
let name = modeldata[selectrow!].name
let nextview = segue.destination as? WekiViewController
nextview?.namestring = name!
}