【问题标题】:UISearchBar Staying at top when seguing from tableview resultsUISearchBar 在从 tableview 结果中搜索时保持在顶部
【发布时间】:2016-10-26 11:36:44
【问题描述】:

我使用 2 UINavigationcontrollers 和 2 UITableViewControllers 创建了一个搜索。一个用于显示初始结果,另一个TableViewController 用于显示搜索结果。

这是我认为问题发生的地方。我使用此方法显示 resultsTableViewController,我将其设置为顶视图控制器。

现在,当我从结果视图控制器中切换时,UISearchBar 保持在顶部。当我编码[vc.tableView setDelegate: self];.

它消除了搜索栏停留的问题,但随后搞砸了我需要识别的 didselectrowatindex 路径,因为结果与原始结果和 Tableviewcontroller 的结果不同。

- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
{

    // Set searchString equal to what's typed into the searchbar
    NSString *searchString = self.searchController.searchBar.text;


    [self updateFilteredContentForAirlineName:searchString];

    // If searchResultsController
    if (self.searchController.searchResultsController) {

        UINavigationController *navController = (UINavigationController *)self.searchController.searchResultsController;

        // Present SearchResultsTableViewController as the topViewController
        SearchResultsTableViewController *vc = (SearchResultsTableViewController *)navController.topViewController;

        // Update searchResults
        vc.searchResults = self.searchResults;

        // And reload the tableView with the new data
        [vc.tableView reloadData];
    }
}

这是我模拟的一个项目,其中包含问题。

http://expirebox.com/download/10533c5d386618b95bb39bd1dc886ace.html

【问题讨论】:

  • 您想在进入下一个屏幕时删除搜索栏
  • 不要继续使用推送控制器,这样您就可以在下一个屏幕中删除搜索栏
  • ok 等待将发送代码

标签: ios objective-c uitableview uinavigationcontroller uisearchbar


【解决方案1】:

尝试将您的下一个视图控制器扩展到类。所以我将创建新的数据类并扩展到视图控制器,而不是将此代码粘贴到 didSelectRowAtIndexPath: 方法中

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    data *next=[self.storyboard instantiateViewControllerWithIdentifier:@"datascreen"];
    [self presentViewController:next animated:YES completion:nil];
}

好的兄弟试试这个

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        data *next=[self.storyboard instantiateViewControllerWithIdentifier:@"datascreen"];
[self.navigationController next animated:YES];
}

两个班级都使用此代码。如果有任何问题,请尝试此代码

【讨论】:

  • 用这个方法,我要呈现的视图控制器,我需要推送它。所以有一个导航控制器,你的方式不提供。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-09
  • 2023-03-12
  • 2018-11-18
  • 2014-10-05
  • 1970-01-01
  • 2014-06-20
  • 1970-01-01
相关资源
最近更新 更多