【问题标题】:Using UIRefreshControl with UISearchBar search results将 UIRefreshControl 与 UISearchBar 搜索结果一起使用
【发布时间】:2013-07-28 20:28:51
【问题描述】:

我正在尝试获得类似邮件应用程序的行为,其中有一个 UISearchBar,您可以拉动以刷新搜索结果。目前,我在 IB 中连接了带有 UISearchBar 的搜索显示控制器,并且一切正常(我可以在主 tableview 中刷新并且可以搜索)。

但是当我搜索并尝试拉刷新搜索结果(如邮件应用程序)时,没有UIRefreshControl。查看下面的视频:

Screen Recording

我想我必须将tableViewUISearchBar 设为headerView,但我不能引用UISearchBar,因为它是IB 中搜索显示控制器的一个出口。这是我的UIRefreshControl 代码:

    //Pull to Refresh
    refreshControl = [[UIRefreshControl alloc] init];
    [refreshControl addTarget:self action:@selector(pullToRefresh)      
    forControlEvents:UIControlEventValueChanged];


    [self.carTableView addSubview:refreshControl];

我在包含tableViewUIViewController-viewDidLoad 方法中使用上述代码

【问题讨论】:

    标签: tableview uisearchbar uisearchdisplaycontroller uirefreshcontrol tableheader


    【解决方案1】:

    我通过创建另一个 UIRefreshControl 并将其添加到 UISearchDispayController 解决了这个问题,每次用户在搜索栏中输入我可以在 - (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView 中检测到的搜索文本时。代码如下:

    //in viewDidLoad
    //Pull to refresh in the search
        searchRefreshControl = [[UIRefreshControl alloc] init];
        [searchRefreshControl addTarget:self action:@selector(pullToRefresh) forControlEvents:UIControlEventValueChanged];
    

    然后:

    //in - (void)searchDisplayController:(UISearchDisplayController *)controller didLoadSearchResultsTableView:(UITableView *)tableView
    
    //add the refresh control to the search display controller tableview
        [self.searchDisplayController.searchResultsTableView addSubview:searchRefreshControl];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-06
      相关资源
      最近更新 更多