本文介绍了在iOS中的工具栏中包含UISearchBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在工具栏上的一个.xib文件中放置一个UISearchBar。
i可以将搜索栏拖放到工具栏上,但它显示以下错误。

I am trying to place a UISearchBar on toolbar in an .xib file.i am able to drag and drop the search bar onto the toolbar but it shows the following error.

ControllerName.xib:error:非法配置:UISearchBar嵌入在UIBarButtonItems(只有可用的ub iPad文档)。

请指导我如何将UISearchBar包含在工具栏的xib 。

Please guide me how to include the UISearchBar into the Toolbar in xib.

推荐答案

据我所知,除非你的开发使用 IPAD IPHONE 中的 UIToolBar 中直接添加 UISearchBar ,需要将UISearchBar添加到customView

As far as I know unless you are using IPAD for your development, you can not add UISearchBar directly in UIToolBar in IPHONE , you need to add the UISearchBar to a customView first and then add it to the toolbar programatically

// your searchbar
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(xposition, yposition, width, height)];

//create a customview and make its frame equal to your searchbar
UIView *searchBarView = [[UIView alloc] initWithFrame:searchBar.frame];

// add your searchbar to the custom view
[searchBarView addSubview:searchBar];

//finally add it to your bar item of the toolbar

UIBarButtonItem *searchBarItem =
    [[UIBarButtonItem alloc] initWithCustomView:searchBarView];

这篇关于在iOS中的工具栏中包含UISearchBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 02:42