I am getting the following error.
Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior ()
Tried the following solution , but does not work for me Attempting to load the view of a view controller while it is deallocating... UISearchController
A demo project is available at the link.
- Tap add button in Master controller, add few time-stamps.
- Switch between rows of the Master view controller and you will see the above error.
Code is shown below and can be downloaded from for short time at .
import UIKit
class DetailViewController: UIViewController,UITableViewDataSource,UITableViewDelegate,UISearchResultsUpdating,UISearchBarDelegate {
@IBOutlet weak var basicTable: UITableView!
var tblSearchController:UISearchController!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.tblSearchController = UISearchController(searchResultsController: nil)
self.basicTable.tableHeaderView=self.tblSearchController.searchBar
// self.tblSearchController.edgesForExtendedLayout = (UIRectEdge.Top )
// self.tblSearchController.extendedLayoutIncludesOpaqueBars = true
self.tblSearchController.searchResultsUpdater = self
self.tblSearchController.searchBar.delegate = self
self.tblSearchController.searchBar.sizeToFit()
// self.tblSearchController.searchBar.frame=CGRectMake(0, 0, self.basicTable.frame.size.width, 44.0)
self.tblSearchController.hidesNavigationBarDuringPresentation=true
self.tblSearchController.dimsBackgroundDuringPresentation=true
self.definesPresentationContext=true
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 0
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 0
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let aCell:UITableViewCell! = tableView.dequeueReusableCellWithIdentifier("123")
return aCell
}
func updateSearchResultsForSearchController(searchController: UISearchController) {
print("Begin Update = \(NSStringFromCGRect(self.tblSearchController.searchBar.frame)) \(self.tblSearchController.view.frame) ")
}
func searchBarTextDidBeginEditing(searchBar: UISearchBar) {
print("Begin= \(NSStringFromCGRect(searchBar.frame))")
}
func searchBarTextDidEndEditing(searchBar: UISearchBar) {
print("End=\(NSStringFromCGRect(searchBar.frame))")
}
}