I have two problems with UISearchController
.
I use this setup for UISearchController:
var resultSearchController = UISearchController(searchResultsController: nil)
override func viewDidLoad() {
super.viewDidLoad()
resultSearchController = UISearchController(searchResultsController: nil)
resultSearchController.searchResultsUpdater = self
resultSearchController.dimsBackgroundDuringPresentation = false
resultSearchController.hidesNavigationBarDuringPresentation = false
resultSearchController.searchBar.placeholder = "Traži.."
resultSearchController.searchBar.sizeToFit()
tableView.tableHeaderView = resultSearchController.searchBar
refreshControl = UIRefreshControl()
refreshControl!.attributedTitle = NSAttributedString(string: "Učitaj podatke..")
refreshControl!.backgroundColor = UIColor(red:1, green:0.48, blue:0, alpha:0.3)
refreshControl!.tintColor = UIColor.whiteColor()
refreshControl!.addTarget(self, action: #selector(ArticleTableViewController.getArticleData), forControlEvents: UIControlEvents.ValueChanged)
tableView.addSubview(refreshControl!)
}
First problem
when i click on search bar textfield, UIRefreshControl
shows but it shouldn't:
Second problem
when i search for item, and click on it, i use Storyboard segue to open that item in new viewcontroller, but problem is that search bar is still there on that new VC(first image is searching, second image shows new VC opened):
I found this solution:
override func viewDidLoad() {
super.viewDidLoad()
resultSearchController = UISearchController(searchResultsController: nil)
resultSearchController.searchResultsUpdater = self
resultSearchController.dimsBackgroundDuringPresentation = false
resultSearchController.hidesNavigationBarDuringPresentation = false
resultSearchController.searchBar.placeholder = "Traži.."
resultSearchController.searchBar.sizeToFit()
tableView.tableHeaderView = resultSearchController.searchBar
refreshControl = UIRefreshControl()
refreshControl!.attributedTitle = NSAttributedString(string: "Učitaj podatke..")
refreshControl!.backgroundColor = UIColor(red:1, green:0.48, blue:0, alpha:0.3)
refreshControl!.tintColor = UIColor.whiteColor()
refreshControl!.addTarget(self, action: #selector(ArticleTableViewController.getArticleData), forControlEvents: UIControlEvents.ValueChanged)
tableView.addSubview(refreshControl!)
// this hide search bar on next VC, first problem
self.definesPresentationContext = true
// second problem
tableView.contentOffset = CGPointMake(0, CGRectGetHeight(resultSearchController.searchBar.frame));
}