我收到以下錯誤。UISearchController - 警告試圖加載視圖控制器的視圖
嘗試而它是 解除分配是不允許的,並且可能導致未定義的行爲()
嘗試了以下解決方案,但對於我Attempting to load the view of a view controller while it is deallocating... UISearchController
不起作用加載視圖控制器的視圖演示項目可在鏈接中找到。
- 點擊主控制器中的添加按鈕,添加幾個時間戳。
- 在主視圖控制器的行之間切換,您將看到上述錯誤。
代碼如下所示,可以從簡稱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))")
}
}
這可能無法解決問題,但最好調用'sizeToFit()'和_then_將搜索欄放到您的界面中。 – matt
我有同樣的問題。如果你找到解決方案,請發佈。 – emresancaktar