gpt4 book ai didi

ios - 无法在 UISearchController 中选择搜索结果

转载 作者:行者123 更新时间:2023-12-01 22:18:01 25 4
gpt4 key购买 nike

我有一个 tableView在我的 IOS 应用程序中列出。我想搜索我的tableView列出 UISearchController .默认情况下,列表将正确显示。

当我激活搜索 Controller (单击 UISearchController )时,我现有的列表将消失,当我输入相关关键字时,结果将相应显示。

但是当我查看相关搜索结果时,searchController将被停用并返回默认列表。

任何的想法?

- (void)viewDidLoad {
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.delegate = self;

self.searchController.searchBar.delegate = self;

self.searchController.searchBar.barTintColor = ThemeLightGrayColor;

self.searchController.hidesNavigationBarDuringPresentation = NO;

[self.searchController.searchBar.layer setBorderColor:[UIColor colorWithRed:229.0/255 green:229.0/255 blue:229.0/255 alpha:1].CGColor];
[self.searchController.searchBar setPlaceholder:@"Search"];
[self.searchController.searchBar.layer setBorderWidth:0.5];
[self.searchController.searchBar setKeyboardType:UIKeyboardTypeDefault];
[[UITextField appearanceWhenContainedInInstancesOfClasses:@[[UISearchBar class]]] setDefaultTextAttributes:@{ NSFontAttributeName: [UIFont fontWithName:@"Bitter" size:14]}];

[self.searchController.searchBar sizeToFit];


_searchResultArr=[NSMutableArray array];
_tableView.tableHeaderView = ({
UIView *view = [[UIView alloc] init];
view.frame = CGRectMake(0, DCNaviH, 0, self.searchController.searchBar.frame.size.height + 50);
_segPromotion = [[UISegmentedControl alloc] initWithItems:@[@"All",@"Near Me",@"Coming Soon"]];
_segPromotion.selectedSegmentIndex = 0;
_segPromotion.backgroundColor = ThemeWhiteColor;
_segPromotion.frame = CGRectMake(10, self.searchController.searchBar.frame.origin.y+5 + self.searchController.searchBar.frame.size.height , ScreenW-20, 30);
[_segPromotion setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"Bitter" size:13],NSForegroundColorAttributeName: ThemeDarkBlueColor } forState:UIControlStateNormal];
[_segPromotion setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"Bitter" size:13],NSForegroundColorAttributeName : ThemeWhiteColor} forState:UIControlStateSelected];
[_segPromotion addTarget:self action:@selector(SegmentChangeViewValueChanged:) forControlEvents:UIControlEventValueChanged];

[view addSubview:self.searchController.searchBar];
[view addSubview:_segPromotion];
view;
});
[self.view addSubview:_tableView];
}


- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
NSString *searchString = searchController.searchBar.text;
[self searchForText:searchString];
[self.tableView reloadData];
}



- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
[self updateSearchResultsForSearchController:self.searchController];
}

- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope
{
[self updateSearchResultsForSearchController:self.searchController];
}


- (void)searchForText:(NSString *)searchString
{
[self filterContentForSearchText:searchString
scope:[self.searchBar scopeButtonTitles][self.searchBar.selectedScopeButtonIndex]];
}

最佳答案

你要做的就是添加self.searchController.obscuresBackgroundDuringPresentation = NO;初始化 searchController 时。

这是因为,正如您所使用的 [[UISearchController alloc] initWithSearchResultsController:nil] ,结果将显示在同一个 View Controller 中(因为 nil 参数)。因此,如果 obscuresBackgroundDuringPresentation设置为 YES (默认情况下是这种情况),结果区域将不可触摸。

关于ios - 无法在 UISearchController 中选择搜索结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51077919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com