2

There is one button on my navigation bar. When I clicked on it, it used to open an alertsheet with a search option. Clicking on the search button would trigger a popover with a tableView and a textField in it.

Searching something in the textField and clicking on the search button would populate the tableView with data coming from the server. But after loading all the data, it crashes with this exception.

Exception:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller Irving. SearchViewController: 0x7fe655d3c7d0.'

This is the popover view-link image

I am very new to IOS swift and I have seen other answers, but I was unable to get those things. I have refered below links, but I am still unable to get those things. Please help me out with this, thanks in advance. Give me brief idea about this.

How to prevent present modally an active controller?

My code :

let Search = UIAlertAction(title: "Search", style: .default) { (action) in
     let popOverVC = UIStoryboard(name: "Main", bundle: nil)
            .instantiateViewController(withIdentifier: "search_popover") as! SearchViewController
     self.addChildViewController(popOverVC)
     popOverVC.view.frame = self.view.frame
     self.view.addSubview(popOverVC.view)
     popOverVC.didMove(toParentViewController: self)
}
sheet.addAction(Search)
sheet.addAction(cancel_button)
present(sheet, animated: true, completion: nil)
regina_fallangi
  • 2,080
  • 2
  • 18
  • 38
Ashish yadav
  • 117
  • 2
  • 11

0 Answers0