gpt4 book ai didi

ios - 警告 : Attempt to present * on * which is already presenting (null)

转载 作者:IT王子 更新时间:2023-10-29 05:01:20 29 4
gpt4 key购买 nike

这是我的第一个 iOS 应用程序。

所以我有一个 UIVIewController 和一个 UITableView,其中我按顺序集成了一个 UISearchBar 和一个 UISearchController过滤要显示的 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()
}

我还使用模态转场来打开元素的 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)
})
}

最佳答案

我找到了解决方案。

我在 HomeViewController.viewDidLoad 中添加了以下代码,并且有效!

definesPresentationContext = true

关于ios - 警告 : Attempt to present * on * which is already presenting (null),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32696615/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com