单击后,UISearchController搜索栏消失

时间:2020-01-16 10:24:09

标签: ios objective-c iphone

我的申请中有UISearchController

self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
[self.searchController setSearchResultsUpdater:self];
[self.searchController setDelegate:self];

if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.1")) {
    self.searchController.obscuresBackgroundDuringPresentation = NO;
}

self.searchController.searchBar.showsCancelButton = YES;

[self.searchBarView addSubview:self.searchController.searchBar];
self.searchController.searchBar.delegate = self;

问题是,当我单击搜索栏后,它从屏幕上消失了: enter image description here enter image description here

有什么主意我可以解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

将这些代码行添加到您的controller

 self.searchController.hidesNavigationBarDuringPresentation = NO;
 self.searchController.dimsBackgroundDuringPresentation = NO;
 self.definesPresentationContext = YES;

希望它将解决您的问题...如果没有,请在评论中让我知道