這是我第一次在iOS上使用。警告:嘗試在*上顯示*(已提交)(空)
所以我有一個UIVIewController
與UITableView
,我已經集成了一個UISearchBar
,並以過濾TableCells顯示
override func viewDidLoad() {
menuBar.delegate = self
table.dataSource = self
table.delegate = self
let nib = UINib(nibName: "ItemCellTableViewCell", bundle: nil)
table.registerNib(nib, forCellReuseIdentifier: "Cell")
let searchButton = UIBarButtonItem(barButtonSystemItem: .Search, target: self, action: "search:")
menuBar.topItem?.leftBarButtonItem = searchButton
self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
return controller
})()
self.table.reloadData()
}
我爲了打開也使用模式賽格瑞一個UISearchController
元素的ViewController
哪裏我將顯示元素的細節。
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.index = indexPath.row
self.performSegueWithIdentifier("ItemDetailFromHome", sender: self)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "ItemDetailFromHome") {
let settingsVC = segue.destinationViewController as! ItemDetailViewController
settingsVC.parent = self
if self.isSearching == true && self.searchText != nil && self.searchText != "" {
settingsVC.item = self.filteredItems[self.index!]
} else {
settingsVC.item = self.items[self.index!]
}
}
}
直到我嘗試顯示ItemDetailViewController
的過濾元件(通過UISearchController
)工作正常。
我有以下消息:
Warning: Attempt to present <ItemDetailViewController: *> on <HomeViewController: *> which is already presenting (null)
在每一個我要去ItemDetailViewController.viewDidLoad()
功能的時間,但之後當搜索被激活我以前的錯誤。
有什麼想法?我試圖使用下面的異步調度,但沒有成功
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.index = indexPath.row
dispatch_async(dispatch_get_main_queue(), {() -> Void in
self.performSegueWithIdentifier("ItemDetailFromHome", sender: self)
})
}
如果你是從的tableview控制器不需要調用self.performSegueWithIdentifier(」設置ItemDetailFromHome ItemDetailFromHome「,sender:self)in index select path in index path – Johnykutty
實際上'ItemDetailViewController'將是一個由幾個segue/viewController(相互關聯)使用的視圖。 – Splendf
太棒了,我該怎麼做?在cellForRowAtIndexPath? 我剛剛看到了一些有關performSegue – Splendf