【问题标题】:When using UISearchDisplayController the popover does not show on an iPad view controller使用 UISearchDisplayController 时,弹出框不会显示在 iPad 视图控制器上
【发布时间】:2014-08-04 17:05:29
【问题描述】:

我在 UIViewController 中创建了一个 UISearchDisplayController,它位于 UINavigationController 中。

我用的是普通的初始化:

self.displayController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self];
self.displayController.searchResultsDataSource = self;
self.displayController.searchResultsDelegate = self;
self.displayController.delegate = self;
self.displayController.displaysSearchBarInNavigationBar = YES;

这段代码运行良好,在 iPhone 中显示暗淡的视图,但在 iPad 上它什么也不做。我在网上看,大多数人都说它应该自动显示一个带有结果的弹出窗口。我根本看不到这种情况发生。我是否必须为 iPad UIViewControllers 以不同的方式执行此操作?

我正在以编程方式创建这一切。

【问题讨论】:

    标签: ios ipad


    【解决方案1】:

    在 iPad 和 iOS7 的模态视图控制器(PageSheet 样式)中使用 UISearchDisplayController 时,我注意到了同样的问题:UISearchDisplayController 不会像在 iPhone 上那样将自身附加到视图控制器的视图层次结构中。

    作为一种不干净但有效的解决方法,您可以在其中一个委托方法中将 UISearchDisplayController 生成的 tableView 附加到您的视图层次结构中:

    - (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView
    {
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
        {
            tableView.frame = self.view.frame;
            [self.view addSubview:tableView];
        }
    }
    

    有两个注意事项:

    1. 您必须自己创建和显示暗淡的视图,只需在 self.view 上创建一个具有黑色背景颜色和 50% alpha 的视图,具有相同的帧大小
    2. 您可能需要修复 UISearchDisplayController 提供的表格视图的内容插入。

    例如:

    - (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView 
    {
        tableView.contentInset = UIEdgeInsetsMake(44.f, 0.f, 0.f, 0.f); 
    }
    

    【讨论】:

      猜你喜欢
      • 2014-10-20
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-13
      • 1970-01-01
      • 2021-06-24
      相关资源
      最近更新 更多