UISearchBar 的取消和清除按钮在 iOS 7 中不起作用 [英] UISearchBar's Cancel and Clear Buttons Not Working in iOS 7

查看:19
本文介绍了UISearchBar 的取消和清除按钮在 iOS 7 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 xCode 项目,其中包含一个带有搜索栏和搜索显示控制器"的 tableview,以允许用户细化显示项目的列表.一般来说,http://www.raywenderlich.com 中提供的指南遵循/16873/how-to-add-search-into-a-table-view.我最近下载了支持 iOS 7 的最新 xCode(版本 5.0 (5A1413)),并一直在不同目标上测试相关应用.

I have an xCode project that contains a tableview with a "Search Bar and Search Display Controller" to allow the user to refine the list of displayed items. In general, the guidance provided in http://www.raywenderlich.com/16873/how-to-add-search-into-a-table-view was followed. I recently downloaded the latest xCode (Version 5.0 (5A1413)) with iOS 7 support and have been testing the app in question on different targets.

在 iOS 6 目标(模拟器或真实设备)上运行此应用程序时,它按预期工作,这意味着按下取消按钮会删除搜索栏并按下清除按钮(小灰色 x)已清除所有搜索条件由用户输入.但是当项目在 iOS 7 目标上运行时,清除和取消按钮都不起作用.

When running this app on an iOS 6 target (emulator or real device), it works as expected meaning that pressing the cancel button removes the search bar and pressing the clear button (little gray x) clears all of the search criteria already typed in by the user. But when the project is run on an iOS 7 target both the clear and cancel button do not work.

本项目中实现了searchBarCancelButtonClicked方法,我已经验证在目标运行iOS 7时不会调用.

The searchBarCancelButtonClicked method is implemented in this project, and I have verified that it is not called when the target is running iOS 7.

- (void)searchBarCancelButtonClicked:(UISearchBar *)SearchBar
{
    NSLog(@"searchBarCancelButtonClicked called");

    self.searchBar.text = nil;

    …

    // Hide Search bar when cancelled
    [self hideSeachBar];

    [self.searchBar resignFirstResponder];

    …
    }

我的表视图控制器设置为 UISearchDisplayDelegate 和 UISearchBarDelegate.看起来这仍然有效,因为 searchBar:textDidChange: 在 iOS 6 或 7 目标上被调用.

My table view controller is setup to be the UISearchDisplayDelegate and UISearchBarDelegate. And it appears that this is still working as searchBar:textDidChange: is called on either a iOS 6 or 7 target.

@interface ItemViewController () <UISearchDisplayDelegate, UISearchBarDelegate>
…
@end

我看不到与此相关的任何其他帖子或任何 iOS 7 更改材料(例如 https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TransitionGuide/Bars.html#//apple_ref/doc/uid/TP40013174-CH8-SW1),其中提到了支持 iOS7 所需的任何重新编码.

I cannot see any other posts related to this or any iOS 7 change material (like https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TransitionGuide/Bars.html#//apple_ref/doc/uid/TP40013174-CH8-SW1) that mentions any recoding that needs to be done to support iOS7.

对此有什么想法吗?谢谢

Any thoughts on this? Thanks

推荐答案

我也有同样的问题,我尝试了以下代码.请试试这个.

I have the same problem, I tried with the following code. Please try this one.

-(void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller
{
    controller.active = YES;

    [self.view addSubview:controller.searchBar];
    [self.view bringSubviewToFront:controller.searchBar];
}

- (void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView  {

    tableView.frame = self.archiveListTblView.frame;
}

- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller
{
    controller.active=NO;

    [self.view addSubview:controller.searchBar];
}

这篇关于UISearchBar 的取消和清除按钮在 iOS 7 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆