gpt4 book ai didi

ios - 推送另一个 View Controller 后,searchBar 不会隐藏

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:02:37 25 4
gpt4 key购买 nike

我在表的标题 View 中创建了一个搜索栏:

self.searchResults = [NSMutableArray arrayWithCapacity:[self.list count]];
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.searchBar.barTintColor = [UIColor clearColor];
self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 44.0);
[[UIBarButtonItem appearanceWhenContainedIn: [UISearchBar class], nil] setTintColor:[UIColor whiteColor]];
[self.searchController.searchBar becomeFirstResponder];

当点击 TableView 中的某一行时,将推送一个新的 View Controller 。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSLog(@"HEY ROW %ld", indexPath.row+1);
ZLContainerViewController *controller = [[ZLContainerViewController alloc]init]; // a container for UIPage
[self.navigationController pushViewController:controller animated:YES];
}

但是,推送新的 View Controller 后,搜索栏仍然存在。我该如何解决这个问题?

非常感谢任何建议!

最佳答案

viewDidLoad 中使用下面的代码。

swift :

self.definesPresentationContext = true

objective-C :

self.definesPresentationContext = YES;

这解决了我的问题。

关于ios - 推送另一个 View Controller 后,searchBar 不会隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27688662/

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