我遇到了最奇怪的显示错误UISearchBar
.
这是我的代码,在另一个应用程序中完美运行。 (我在代码中创建搜索栏,因为 xib 文件不可行。)
searchBar = [[UISearchBar alloc] initWithFrame:
CGRectMake(0, 0, self.tableView.frame.size.width, 44)];
searchBar.delegate = self;
searchController = [[UISearchDisplayController alloc]
initWithSearchBar:searchBar contentsController:self];
searchController.delegate = self;
searchController.searchResultsDataSource = self;
searchController.searchResultsDelegate = self;
self.tableView.tableHeaderView = searchBar;
搜索功能等工作正常。但奇怪的是,搜索栏在设备和模拟器上看起来都是这样的:
- 占位符字符串不应该出现在那里,而应该位于右侧。
- 当我输入搜索文本时,它也从太左开始,放大镜图标显示出来。
- 另外,设置
searchBar.placeholder
or searchBar.prompt
to @""
or nil
不会删除此“搜索”占位符。 (然而,一个
searchBar.placeholder = @"FooBar";
将显示“FooBar”,但位置仍然错误。
- 最后,我发现奇怪的是,尽管我已将语言设置为其他语言(例如德语),但该字符串是“Search”。
有什么帮助吗?最紧迫的问题是让文本位于右侧。
该行为可能是由覆盖任一引起的(CGRect)editingRectForBounds:(CGRect)bounds
or - (CGRect)textRectForBounds:(CGRect)bounds
。您是否更改了其中的任何一个UITextField
您的应用程序中其他地方的类别?这样做的目的可能是向文本字段添加填充(这可以通过不可见的方法来完成)leftView
)。在这种情况下,您的自定义“填充”将应用于UISearchBar
文本域。
这样的一个类别在UITextField
还会导致您的应用程序在初始化使用的框架类时崩溃UITextField
, 例如MFMailComposeViewController
,因此出于多种原因,这是一个坏主意。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)