【问题标题】:UISplitViewController with new UISearchController issue with UISearchBarUISplitViewController 与 UISearchBar 的新 UISearchController 问题
【发布时间】:2014-11-28 12:57:58
【问题描述】:

我最近开始重写我的 iOS 应用程序以使用新的 UISearchController 和通用故事板。 我的应用程序可用于两种设备(iPhoneiPad),因此使用 UISplitViewController 更改通用情节提要是一大优势。

但遗憾的是,UISearchController 没有按预期工作。我用以下几行添加了UISearchController

self.searchController = UISearchController(searchResultsController: nil)
self.searchController.searchBar.sizeToFit()
self.searchController.dimsBackgroundDuringPresentation = false
self.myTableView.tableHeaderView = self.searchController.searchBar
self.searchController.searchResultsUpdater = self
self.definesPresentationContext = true

我的控制器链是这样的:

UISplitViewController
    UITabbarController (Master)
        UINavigationController
            UITableViewController
    UINavigationController (Detail)
        UINavigationController
            UIViewController

问题在于,在 iPad 应用程序中,UISearchBarUINavigationBar 覆盖。但是,如果我切换选项卡并返回视图。 UISearchBar 可见。因此,在切换选项卡栏后,它会以某种方式正确重绘视图。在 iPhone 版本中,它会自动正确运行。

iPad 应用程序

第一次启动后,UISearchBarUINavigationBar 覆盖

切换标签后UISearchBar正确显示

iPhone 应用

iPhone 应用程序在不更改选项卡的情况下正常工作..

我尝试了什么:

  • 使用扩展边缘的不同设置
  • 在 viewWillAppear 方法中添加 SearchController,因为我想我可以通过稍后添加搜索控件来欺骗它

【问题讨论】:

    标签: ios swift ios8 uisplitviewcontroller uisearchcontroller


    【解决方案1】:

    我假设你在 viewDidload 中设置了搜索控制器 self.searchController.searchBar.sizeToFit()。除此之外,您需要添加此方法(Objective-C 代码):

    - (void)viewDidLayoutSubviews {
        // you could check
        // if (IS_IPAD || (IS_IPHONE_6PLUS && UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))) 
        [self.searchController.searchBar sizeToFit];
    }
    

    如果它不起作用,您可以将这些代码添加到您的viewDidlLoadviewDidLayoutSubviews

    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.yourTableViewController.edgesForExtendedLayout = UIRectEdgeNone;
    

    如果你想停靠你的搜索,请参考我的回答here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多