Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c UINavigationController中的UISearchBar(带取消按钮)不可选择_Objective C_Ios_Uinavigationcontroller_Focus_Uisearchbar - Fatal编程技术网

Objective c UINavigationController中的UISearchBar(带取消按钮)不可选择

Objective c UINavigationController中的UISearchBar(带取消按钮)不可选择,objective-c,ios,uinavigationcontroller,focus,uisearchbar,Objective C,Ios,Uinavigationcontroller,Focus,Uisearchbar,我已经在UINavigationController中添加了一个UISearchBar,但只要将“取消”按钮添加到搜索栏中,我就无法再通过触摸它来选择它 我用来创建搜索栏并添加它的代码是: UISearchBar *theSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0f,0.0f,320.0f,0.0f)]; theSearchBar.delegate = self; [theSearchBar setPlacehold

我已经在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容器中,但这也没有解决问题

如果添加“取消”按钮可能会导致此操作失败,该怎么办

更新:
我最终没有使用“取消”按钮,因为我确定搜索栏的使用方式是不必要的。

我绝对建议使用UISearchDisplayController:
它有一个内置的取消按钮,通过将其放置在interface builder中,可以节省大量代码。更少的代码=更少的bug。

我肯定会推荐一个UISearchDisplayController: 它有一个内置的取消按钮,通过将其放置在interface builder中,可以节省大量代码。更少的代码=更少的bug