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

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

问题描述

我有一个xCode项目,其中包含一个带有搜索栏和搜索显示控制器的表视图,以允许用户优化显示的项目列表。一般而言, http://www.raywenderlich.com提供的指导/ 16873 /如何添加搜索到表格视图。我最近下载了支持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目标上运行时,clear和cancel按钮都不起作用。

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.

对此有何想法?谢谢

推荐答案

我遇到同样的问题,我尝试使用以下代码。请尝试这个。

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天全站免登陆