[英]iOS 7 Search Bar - Cancel button doesn't work
我在iOS 6應用程序中有一個UISearchBar
,它運行良好,但在iOS 7中,取消按鈕和清除按鈕不起作用,我無法返回。 這是我的應用程序中的一個大問題,我需要解決它。
我的代碼是:
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
// -- iOS 7 Hack
if (!SYSTEM_VERSION_LESS_THAN(@"7.0")) {
controller.searchResultsTableView.frame = CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height-64);
[controller.searchContentsController.view setNeedsLayout];
}
[self filterContentForSearchText:searchString scope:nil];
return YES;
}
- (void) searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView {
// iOS7 Hack
if (!SYSTEM_VERSION_LESS_THAN(@"7.0")) {
controller.searchResultsTableView.contentInset = UIEdgeInsetsMake(0.f, 0.f, 0.f, 0.f);
}
}
謝謝你提前。
Possbile重復: UISearchBar的取消和清除按鈕在iOS 7中不起作用
編輯:
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
self.searchDisplayController.searchBar.hidden = YES;
self.tempImageView.hidden = NO;
[searchBar resignFirstResponder];
}
解:
有了這個功能,我解決了這個問題:
-(void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller
{
controller.active = YES;
[self.view addSubview:controller.searchBar];
[self.view bringSubviewToFront:controller.searchBar];
}
希望能幫助到你!
IOS 7默認搜索欄將是透明取消按鈕
- (void)searchBarCancelButtonClicked:(UISearchBar *)aSearchBar
{
[aSearchBar resignFirstResponder];
isSearching = NO;
aSearchBar.text = @"";
[diaryTableView reloadData];
}
有了這個功能,我解決了這個問題:
-(void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller
{
controller.active = YES;
[self.view addSubview:controller.searchBar];
[self.view bringSubviewToFront:controller.searchBar];
}
希望能幫助到你!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.