按下取消按钮后如何保持范围栏? [英] How to keep scopebar even after pressed Cancel button?

查看:166
本文介绍了按下取消按钮后如何保持范围栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITableView,顶部有一个搜索栏。我使用UISearchDisplayController来实现相同的功能。它还有一个带两个按钮的示波器栏。默认情况下,当我启动应用程序时,将显示范围栏。当我在搜索后单击取消按钮时,示波器条消失了。因此,即使按下取消按钮后,还有什么方法可以保留范围栏。我使用了以下代码,但它不起作用。

I have a UITableView with a searchbar on the top. I used UISearchDisplayController for implementing the same. And also it has a scope bar with two buttons. In default when I launch the app, the scope bar will be displayed. When I click the cancel button after the searching, the scopebar disappeared. So is there any way to keep the scopebar even after I pressed the Cancel button. I used the following code but its not working.

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
{
    [searchBar setShowsScopeBar:YES];
    return YES;
}

谢谢:)

推荐答案

我今天遇到了问题,我想我找到了解决办法。

I've had the problem today and I think I've found a solution.

你需要做两件事:


  1. 设置showsScopeBar后,在searchBar上调用'sizeToFit'。这将确保正确设置searchBars框架以包含范围栏。

  2. 不幸的是,当searchBar调整大小并导致范围栏与第一个重叠时,表视图似乎不喜欢它细胞。要解决此问题,您可以将tableHeaderView重新设置为searchBar(再次),这似乎可以解决重叠问题。

最终代码:

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
{
    self.searchBar.showsScopeBar = YES;
    [self.searchBar sizeToFit];
    self.tableView.tableHeaderView = self.searchBar;
    return YES;
}

这篇关于按下取消按钮后如何保持范围栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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