搜索栏取消按钮有时在ios 7中不起作用 [英] Search Bar Cancel Button don´t work in ios 7 sometimes

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

问题描述

取消按钮在iOS 7中不起作用。

Cancel button in search bar don´t work in iOS 7 when search bar is initially hidden.

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

I follow this tutorial to create a search bar in tableview:

raywenderlich教程

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

There are a example project in this tutorial, is better use this project than my explanation :)

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

In iOS 5 and 6 works fine. I have reviewed all delegates.

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

There are two possibilities. The first is to press the button when the bar is hidden, the second is to press the button when the bar is displayed (moving the table down with a gesture you can see the search bar)

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

If search bar is hidden initially cancel button don´t work, it don't call calcel delegate method:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar

抱歉,我无法解释它。

谢谢

推荐答案

我在互联网上搜索,无法找到一个办法。所以我更改了UItableview行为。

I googled all over internet and couldn't find a solution. so i changed the UItableview behaviour.

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

instead of [searchBar becomeFirstResponder]; I scroll down the tableview.

- (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];


}

//        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中,更改表格视图边界会导致搜索栏消失。
希望有所帮助。

If found for some reasons, in iOS 7 , change table view bounds cause search bar to disappear. Hope that helps.

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

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