UISearchDisplayController
有一个boolean
叫做的财产displaysSearchBarInNavigationBar
.在iOS 8中,我的搜索栏向上移动了什么?非常感谢任何指导.
这是我的代码,我不完全确定为什么这不起作用.当我单击搜索栏时,它会消失,而不是移动自身和导航栏.
import UIKit
class ViewController: UIViewController, UISearchResultsUpdating, UISearchControllerDelegate, UISearchBarDelegate, UITableViewDelegate, UITableViewDataSource {
let searchController = UISearchController(searchResultsController: nil)
var tableView = UITableView()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.searchController.searchResultsUpdater = self
self.searchController.delegate = self
self.searchController.searchBar.delegate = self
self.searchController.hidesNavigationBarDuringPresentation = true
self.searchController.dimsBackgroundDuringPresentation = true
tableView.dataSource = self
tableView.delegate = self
self.navigationItem.titleView = searchController.searchBar
self.definesPresentationContext = true
self.setupSearchBar()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning() …
Run Code Online (Sandbox Code Playgroud) 我有一个UITableViewController与UISearchBar和UISearchDisplayController.它存在于UIVavigationController中的UIViewController中的Container视图中.我制作了这张图片来帮助描述结构:
这就是它的真实情况:
当我点击搜索栏时,我必须隐藏导航栏.通常情况下,这会自行发生,但由于我的UITableViewController在Container View中,我必须自己处理这个更改.这就是它的样子,注意状态栏是白色的,因为导航栏是白色的,即使它现在是隐藏的.
一旦我开始输入一些搜索文本,结果就会显示出来.如果我向上滚动这些结果,它们会在搜索栏下方传递,但它们与状态栏重叠,这非常没有吸引力.
如果不涉及容器视图,则这一切都按预期工作,并且表内容在状态栏下方传递,但是涉及ContainerView时,表文本和状态栏会发生冲突.
如何使状态栏下的文本正常运行?
uitableview uisearchbar uisearchdisplaycontroller ios uicontainerview
我有一个UISearchController
与UITableViewController
作为searchResultsController
,在UISearchBar
这个searchController
设置是在tableHeaderView
我目前的tableView
在我的根视图控制器显示.正如预期的那样,几乎所有东西都运作良好.但是在动画中UISearchBar
(当我点击searchBar和UINavigationBar
隐藏并且searchBar到达顶部时,如同UISearchDisplayController
)我有一个奇怪的行为.它不会移动到UINavigationBar
(y:0)的位置,而是跳出屏幕而不是启动显示取消按钮的动画.我尝试将我的实例化代码移动到viewDidLoad
而不是init
,事情就是一样的.我认为问题的核心在于searchResultsController
视图的框架,但我不确定(我尝试设置框架,但没有成功).我正在做的一切都是纯粹的代码.
以下是代码的相关部分:
- (void) viewDidLoad {
[super viewDidLoad];
// search controller setup
self.searchController = [[UISearchController alloc] initWithSearchResultsController:self.searchResultsController];
self.searchController.delegate = self;
self.searchController.searchResultsUpdater = self;
self.searchController.searchBar.delegate = self;
[self.searchController.searchBar sizeToFit];
self.tableView.tableHeaderView = self.searchController.searchBar;
self.searchController.definesPresentationContext = YES;
}
Run Code Online (Sandbox Code Playgroud)
我有一个懒惰的负载searchResultsController
:
- (UITableViewController *)searchResultsController {
if (_searchResultsController == nil) {
_searchResultsController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain]; …
Run Code Online (Sandbox Code Playgroud) 我花了很多时间在网上搜索并与其他开发者讨论这个问题无济于事.确切的问题在这篇SO帖子中有所描述(专注于UISearchBar,但键盘没有出现),虽然已经有很多年了.
我最近在IB中使用了已弃用的UISearchDisplayController和UISearchBar,并通过iOS8的代码切换到UISearchController.
然而,我遇到的问题是焦点被正确分配(你可以看出因为取消按钮在视图加载后动画到搜索栏的右侧),但是键盘没有显示出来.
这是我的代码.
.H
@property (nonatomic, strong) UISearchController *searchController;
Run Code Online (Sandbox Code Playgroud)
.M
- (void)viewDidLoad {
[super viewDidLoad];
...
[self initializeSearchController];
....
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.searchController setActive:YES];
[self.searchController.searchBar becomeFirstResponder];
}
- (void)initializeSearchController {
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.delegate = self;
self.searchController.searchBar.delegate = self;
[self.searchController.searchBar sizeToFit];
[self.tableView setTableHeaderView:self.searchController.searchBar];
self.definesPresentationContext = YES;
}
Run Code Online (Sandbox Code Playgroud)
到目前为止我尝试过的东西.
我已经尝试在0.2秒延迟时调用becomeFirstResponder,正如另一篇SO帖子中所建议的那样.
我在viewDidAppear中设置了一个断点,并验证self.searchController和self.searchController.searchBar都是有效对象,都不是.
我已经尝试遵循UISearchControllerDelegate并使用以下代码片段
这里:
- (void)didPresentSearchController:(UISearchController *)searchController {
//no matter what code I put in here to becomeFirstResponder, …
Run Code Online (Sandbox Code Playgroud) 我正在撕裂我的头发.我的客户想要在搜索栏的左侧添加一个按钮,如下例所示:
替代文字http://www.erik.co.uk/images/IMG_0008.PNG
但我无法弄清楚该怎么做.Apple似乎没有提供任何记录方法来向UISearchBar添加自定义按钮,更不用说在搜索栏的左侧.
我已经尝试在Interface Builder中添加一个UIToolbar,左边有一个按钮,但我找不到任何样式的组合,两者排列正确,给人的印象是它们是一个.从下图中可以看出,垂直对齐中总有一个像素差异:
替代文字http://www.erik.co.uk/images/verticalalignment.png
我已经四处寻找,但是找不到答案,但正如我们从截图中看到的那样,它必须是可能的!
预先感谢您的帮助.
埃里克
我的viewController有一个UISearchBar设置为UITableView的标题视图.
self.tableView.tableHeaderView = self.searchBar;
Run Code Online (Sandbox Code Playgroud)
在iOS7中,向下拉超出UISearchBar会显示一个空白区域,它不遵循使用self.tableView.backgroundColor设置的暗色.
有没有办法摆脱白色空间?
我正在尝试使用UISearchController
iOS 8中的新功能,并将其嵌入UISearchBar
到我的UINavigationBar
.这很容易完成如下:
searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.delegate = self
searchController.searchBar.delegate = self
searchController.dimsBackgroundDuringPresentation = false
searchController.hidesNavigationBarDuringPresentation = false
navigationItem.titleView = searchController.searchBar
Run Code Online (Sandbox Code Playgroud)
但是当我添加范围按钮时:
searchController.searchBar.showsScopeBar = true
searchController.searchBar.scopeButtonTitles = ["Posts, Users, Subreddits"]
Run Code Online (Sandbox Code Playgroud)
它添加了背后的按钮UISearchBar
,显然看起来很奇怪.
我该怎么做?
uinavigationcontroller uisearchbar ios ios8 uisearchcontroller
我有一个UISearchBar,它有一个取消按钮(显示使用-(void)setShowsCancelButton:animated
).tintColor
为了获得一个灰色的搜索栏,我已经改变了这样的搜索栏:
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 40)];
searchBar.tintColor = [UIColor colorWithWhite:0.8 alpha:1.0];
Run Code Online (Sandbox Code Playgroud)
这就是它现在的样子 - 注意取消按钮也是灰色的:http://twitpic.com/c0hte
有没有办法分别设置取消按钮的颜色,所以它看起来更像这样:http://twitpic.com/c0i6q
我有一个UISearchDisplayController和UISearchBar从我的笔尖通过Outlets连接到我的ViewController.
我想隐藏取消按钮,以便用户永远不会看到它.问题是以下代码隐藏了按钮,但仅在将其显示给用户一毫秒后(例如,它在模拟器和设备上闪烁然后消失在视图之外).
- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller
{
controller.searchBar.showsCancelButton = NO;
}
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法来隐藏它?
cocoa-touch objective-c uisearchbar uisearchdisplaycontroller ios
从Xcode 5升级到6,现在我的搜索栏色调为黑色.
试图通过故事板右侧窗格>"Bar Tint"更改它以清除颜色,但它仍然是黑色.
也以编程方式尝试:
[self.searchBar setTintColor:[UIColor clearColor]];
Run Code Online (Sandbox Code Playgroud)
还是黑的:(
有任何想法吗?
uisearchbar ×10
ios ×8
objective-c ×4
ios8 ×3
iphone ×3
uitableview ×3
cocoa-touch ×2
ios7 ×1
keyboard ×1
searchbar ×1