objective-c - UISearchDisplayController 与 ViewController 问题

标签 objective-c uitableview uisearchdisplaycontroller

我有一个 ViewController,前面有一个导航 Controller ,里面有一个 TableView 和其他元素。 tableView 还有一个搜索栏,在场景中,除了主 ViewController 之外,我还有一个搜索显示 Controller 。

功能正常,但我遇到以下 UI 问题:

  1. 虽然我的主视图具有黑色背景颜色(并且大多数元素具有黑色背景颜色),但是当我向下拖动tableView时,会出现一些空白。

enter image description here

我还有以下 UI 初始设置

-(void) viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];

    self.view.backgroundColor = [UIColor blackColor];
    self.tableView.backgroundColor = [UIColor blackColor];

    self.searchDisplayController.searchResultsTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    self.searchDisplayController.searchResultsTableView.separatorColor = [UIColor blackColor];
    self.searchDisplayController.searchResultsTableView.separatorInset = UIEdgeInsetsMake(0, 12, 0, 12);


    [self.searchDisplayController.searchResultsTableView setBackgroundColor:[UIColor blackColor]];
    [self.searchDisplayController.searchContentsController.view setBackgroundColor:[UIColor blackColor]];
    self.searchDisplayController.searchBar.barStyle = UIBarStyleBlack;
    self.searchDisplayController.displaysSearchBarInNavigationBar = NO;
}
  • 当我搜索结果并将表格向上拖动到搜索栏后时,会出现一个小地方可以看到表格 View 。
  • enter image description here

    有什么想法可以解决这个问题吗:(?

    编辑更新: 两者都已解决,从 TableView 中删除搜索栏。此后出现了另一个问题,即搜索显示 Controller 的动画没有更新搜索栏。这是通过以下帖子解决的: UISearchBar animation issue

    最佳答案

    1. 您必须将 UIView 背景颜色设置为黑色(不仅仅是 UITableView 颜色)。
    2. 您必须将表格 View 放置在 UISearchBar 下方,您可以通过编程方式或通过 IB 来完成此操作。我推荐第二种选择。非常简单。

    关于objective-c - UISearchDisplayController 与 ViewController 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31161978/

    相关文章:

    ios - 覆盖 UIViewController 的 View 属性

    objective-c - NSTable 和 NSMutableArray 排序

    uitableview - 表格单元格字体大小(在 Swift 中)

    ipad - 行比 UITableView 本身更窄

    iPhone SDK : Setting the size of UISearchDisplayController's table view

    iOS:presentViewController 错误不鼓励在分离的 View Controller 上呈现 View Controller

    objective-c - Cocoa 的实时异步任务

    ios - 在 iOS 的 tableView 中插入新行

    ios - UISearchBarDisplayController 与 UINavigationBar 不能很好地配合

    iphone - 即使按下取消按钮后如何保留范围栏?