【发布时间】:2011-10-06 19:39:53
【问题描述】:
我在 UINavigationController 中添加了一个 UISearchBar 就好了,但是一旦我将取消按钮添加到搜索栏,我就无法再通过触摸它来选择它。
我用来创建和添加搜索栏的代码是:
UISearchBar *theSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0f,0.0f,320.0f,0.0f)];
theSearchBar.delegate = self;
[theSearchBar setPlaceholder:@"Search iPad"];
[theSearchBar setShowsCancelButton:YES animated:YES];
self.navigationItem.titleView = theSearchBar;
self.navigationItem.titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[theSearchBar release];
如果我删除添加取消按钮的行,我可以专注于搜索栏并且搜索正常工作。只要我把那条线放进去,它就可以正常显示,但我不能再专注于它了。
我尝试将它放入一个简单的 UIView 容器中,但这也没有解决问题。
如果添加取消按钮会导致此操作失败怎么办?
更新: 我最终没有使用取消按钮,因为我确定搜索栏的使用方式没有必要。
【问题讨论】:
标签: objective-c ios uinavigationcontroller focus uisearchbar