gpt4 book ai didi

ios - 搜索 Display Controller 显示附加的 tableView

转载 作者:行者123 更新时间:2023-11-29 12:52:09 25 4
gpt4 key购买 nike

为什么我在搜索栏中插入一些词后显示另一个表格 View ?

在搜索框里写之前

enter image description here

在搜索框中写入后

enter image description here

这是我使用的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}

if (tableView == self.searchDisplayController.searchResultsTableView) {
cell.textLabel.text = [NSString stringWithFormat:@"%@", filteredFields[indexPath.row]];
}
else
{
cell.textLabel.text = [NSString stringWithFormat:@"%@", oriFields[indexPath.row] ];
}


return cell;
}

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"SELF contains[c] %@", searchText];
filteredFields = (NSMutableArray *)[oriFields filteredArrayUsingPredicate:resultPredicate];
}

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString
scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
objectAtIndex:[self.searchDisplayController.searchBar
selectedScopeButtonIndex]]];

return YES;
}

最佳答案

搜索显示 Controller 管理搜索栏的显示,以及显示搜索结果的 TableView 。

您使用搜索栏和负责管理要搜索的数据的 View Controller 来初始化搜索显示 Controller 。当用户开始搜索时,搜索显示 Controller 将搜索界面叠加在原始 View Controller 的 View 上,并在其 TableView 中显示搜索结果。

apple 引用

关于ios - 搜索 Display Controller 显示附加的 tableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22191658/

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