警告:尝试在已经呈现的 * 上呈现 * (null) [英] Warning: Attempt to present * on * which is already presenting (null)

查看:15
本文介绍了警告:尝试在已经呈现的 * 上呈现 * (null)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This is my first application for iOS.

所以我有一个 UIVIewController 和一个 UITableView,我在其中集成了一个 UISearchBar 和一个 UISearchController过滤要显示的 TableCells

So I have a UIVIewController with a UITableView where I have integrated a UISearchBar and a UISearchController in order to filter TableCells to display

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,我将在其中显示元素的详细信息.

I am using also a modal segue in order to open the element's ViewController where I will display details of the element.

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).

That works fine until I try to display the ItemDetailViewController for a filtered element (through the UISearchController).

我有以下消息:

Warning: Attempt to present <ItemDetailViewController: *>  on <HomeViewController: *> which is already presenting (null)

每次我去 ItemDetailViewController.viewDidLoad() 函数时,但之后当搜索被激活时,我有以前的错误.

At every time I am going to the ItemDetailViewController.viewDidLoad() function but after that when the search is activated I have the previous error.

有什么想法吗?我尝试使用以下异步调度但没有成功

Any idea ? I have tried to use the following async dispatch but without success

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    self.index = indexPath.row
    dispatch_async(dispatch_get_main_queue(), { () -> Void in
        self.performSegueWithIdentifier("ItemDetailFromHome", sender: self)
    })
}

推荐答案

我已经找到了解决方案.

I have found out a solution.

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

I have add the following code in HomeViewController.viewDidLoad and that works !

definesPresentationContext = true

这篇关于警告:尝试在已经呈现的 * 上呈现 * (null)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆