ios - 搜索栏取消按钮有时在 iOS 7 中不起作用

标签 ios ios7 tableview uisearchbar

当搜索栏最初隐藏时,搜索栏中的取消按钮在 iOS 7 中不起作用。

我按照本教程在 tableview 中创建一个搜索栏:

raywenderlich tutorial

本教程中有一个示例项目,使用这个项目比我的解释更好:)

在 iOS 5 和 6 中工作正常。 我已经审核了所有代表。

有两种可能。第一种是隐藏栏时按下按钮,第二种是显示栏时按下按钮(用手势向下移动表格可以看到搜索栏)

如果搜索栏最初是隐藏的,取消按钮不起作用,它不会调用 calcel 委托(delegate)方法:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar

抱歉,我无法解释得更好。

谢谢

最佳答案

我在互联网上搜索了所有内容,但找不到解决方案。所以我改变了 UItableview 的行为。

而不是 [searchBar becomeFirstResponder]; 我向下滚动表格 View 。

- (IBAction)goToSearch:(id)sender {

 scroll down to show the table.
//    CGRect newBounds = self.tableView.bounds;
//    newBounds.origin.y =0;
//    
//    self.tableView.bounds = newBounds;
//[searchBar becomeFirstResponder];

    CGPoint contentOffset=self.tableView.contentOffset;
    contentOffset.y=0;
    [self.tableView setContentOffset:contentOffset animated:YES];


}

在我的 ViewDidload 中:

//        CGRect newBounds = self.tableView.bounds;
//        newBounds.origin.y = newBounds.origin.y + searchBar.bounds.size.height;
        // self.tableView.bounds = newBounds;

        CGPoint contentOffset=self.tableView.contentOffset;
        contentOffset.y=self.tableView.bounds.origin.y + searchBar.bounds.size.height;
        self.tableView.contentOffset=contentOffset;

如果由于某些原因发现,在 iOS 7 中,更改表格 View 边界会导致搜索栏消失。 希望对您有所帮助。

关于ios - 搜索栏取消按钮有时在 iOS 7 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19245779/

相关文章:

ios - 使 ios7 BLE 外设在后台工作

ios - TableView 不从数据库重新加载数据

swift - 当我从 TableView 和核心数据中删除时应用程序崩溃

ios - 当我的应用程序通过 UITabBar 完成启动时,如何将加载的数据传递到 UITableView?

ios - 角标(Badge)数量始终为1(云函数)

objective-c - 在 iOS 7 中自定义导航栏 - 标题颜色不起作用

ios - UIWebview 键盘返回键按下 ios 7

ios - 如何在 iOS 13.3 上使用 xib 显示 UITableViewCell?

ios - 如何判断当前线程是否创建为 NSThread?

android - 通过电子邮件中的链接打开 Facebook 应用程序