UISearchBar和UINavigationItem [英] UISearchBar and UINavigationItem

查看:52
本文介绍了UISearchBar和UINavigationItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法获得UISearchBar来将自己从导航栏中的最左边移到最右边.在-(void)viewDidLoad方法中,我有以下代码:

I can't seem to get a UISearchBar to position itself from the far left to the far right in the navigation bar. In the -(void)viewDidLoad method, I have the following code:

UISearchBar *sb = [[UISearchBar alloc] initWithFrame:self.tableView.tableHeaderView.frame];
sb.delegate = self;
self.navigationItem.titleView = sb;
[sb sizeToFit];
[sb release];

构建和运行时,乍一看似乎还不错.但是,更仔细地看,您可以知道左侧有一个边距/空格.在宏伟的方案中,这并不是什么大问题,但是当我点击搜索栏开始搜索时,我将取消按钮设置为动画.由于搜索栏的位置略微偏右,因此动画是生涩的,而取消"按钮则从末端掉下来,如下所示:链接文本

When you build and run, it looks just fine at first glance. However, looking more closely, you can tell there is a margin/space on the left. This wouldn't be a big deal in the grand scheme of things, but when I tap the search bar to start a search, I animate the cancel button into view. Because the search bar is positioned slightly to the right, the animation is jerky and the cancel button falls off the end like so: link text

UINavigationItem好像是一个具有三个单元格的表,在第一个和最后一个有一个无法删除的填充处-似乎也没有一种将其全部合并"的方法,然后将搜索栏放在此处.我知道这种外观是可能的,因为AppStore搜索在导航栏中有一个搜索栏,并且一直到边缘.有谁知道如何使搜索栏一直延伸到边缘,以便我的滑入式取消按钮动画可以正常工作?

It seems as if the UINavigationItem is like a table with three cells, where there is a padding on the first and last which I can't remove - nor does there seem to be a way to 'merge' it all together and then place the search bar there. I know this look is possible, because the AppStore search has a search bar in the navigation bar and it goes all the way to the edges. Anyone know how to get the search bar to go all the way to the edges so my slide-in cancel button animation will work properly?

推荐答案

我想我找到了答案-尽管我尚未测试验证.在上面提供的问题中,我具有以下结构:

I think I found out the answer - though I haven't tested to verify. In the issue I provided above, I have the following structure:

标签栏控制器->导航控制器->视图控制器

tab bar controller -> navigation controller -> view controller(s)

有问题的搜索栏位于视图控制器中,而视图控制器又位于导航控制器中,而导航控制器位于选项卡栏中.

The search bar in question was in a view controller, which in turn was in the navigation controller, which navigation controller is in the tab bar.

我正在随便看斯坦福CS 193P(2009年春季)课程,在第13课结束时,答案可能已经提出.Alan Cannistraro表示,Presence应用程序的结构应具有以下结构:

I was casually watching the Stanford CS 193P (Spring 2009) courses and at the end of Lecture 13, the answer may have been presented. Alan Cannistraro stated that the structure of the Presence app should have this structure:

此结构http://img143.imageshack.us/img143/6/viewcontrollerstructure.jpg

其中,底视图控制器(与标签栏控制器相邻)是具有搜索栏控件的视图控制器.他警告说,如果不这样做的话,您会遇到问题".我可能遇到的问题是?我相信.

where the bottom view controller (adjacent to the tab bar controller) was the view controller which had the search bar control. He warned if it's not done in this fashion, you'll "run into problems". Possibly the problem I faced? I believe so.

这篇关于UISearchBar和UINavigationItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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