【问题标题】:Swift: UISearchController not in the window hierachySwift:UISearchController 不在窗口层次结构中
【发布时间】:2016-05-12 07:08:57
【问题描述】:

我在 UITableViewController 上添加了一个搜索栏,但每次单击搜索栏时都会出错。视图也变黑了..

警告:尝试在 FindViewController 上显示 OWSearchController:其视图不在窗口层次结构中!

我尝试在 viewDidLoadviewDidAppear 中配置 SearchController ,结果相同。

class FindViewController: UITableViewController {

    var searchController: OWSearchController!

    override func viewDidAppear(animated: Bool) {
        self.configureSearchController()
    }

    func configureSearchController() {

        // Create the search controller and make it perform the results updating.
        searchController = OWSearchController(searchResultsController: self)
        searchController.hidesNavigationBarDuringPresentation = false


        // Configure the search controller's search bar.
        searchController.searchBar.searchBarStyle = .Minimal
        searchController.searchBar.placeholder = NSLocalizedString("Search", comment: "")

        // Include the search bar within the navigation bar.
        navigationItem.titleView = searchController.searchBar
        definesPresentationContext = true
    }
}

有人可以帮我看看它有什么问题吗?非常感谢

【问题讨论】:

    标签: swift uisearchcontroller


    【解决方案1】:

    这是我项目的工作代码副本

    func displayContentController(content: DrawingViewController) {
        self.addChildViewController(content)
        let drawingFrame = AVMakeRectWithAspectRatioInsideRect(imageView.image!.size, imageView.bounds);
        content.view.frame = drawingFrame;
        imageView.addSubview(content.view); //image view is a self.view child, you may just use self.view?.addSubview(content.view)
        //content.drawingView.reset()
        content.didMoveToParentViewController(self);
    }
    
    func hideContentController(content: DrawingViewController) {
        content.willMoveToParentViewController(nil);
        content.view.removeFromSuperview();
        content.removeFromParentViewController();
    }
    

    【讨论】:

      猜你喜欢
      • 2015-05-29
      • 2018-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-17
      • 2018-11-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多