调用 searchBarSearchButtonClicked 时,SearchBar 文本为空
我已经在视图控制器中实现了 searchBarSearchButtonClicked 委托方法。
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
searchBar.text = textView.text
}
当单击“搜索”按钮但 searchBar.text 属性为空时,该方法会成功调用。
有什么想法为什么 searchBar.text 会是空的吗?
I've implemented the searchBarSearchButtonClicked delegate method in my view controller
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
searchBar.text = textView.text
}
The method is successfully called when the "Search" button is clicked but the searchBar.text property is empty.
Any ideas why searchBar.text would be empty?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用“searchBar.text”中的值,而不是将“textView.text”的值分配给它。试试这个:
评论这个“searchBar.text = textView.text”并添加“NSLog(@”%@”,searchBar.text);”
现在在您的日志中检查搜索栏的值。如果您已将搜索栏的委托连接到文件的所有者,您还可以检查您的 XIB 文件。
You should use the value from "searchBar.text" instead of assigning the value of the "textView.text" to it. Try this:
Comment this "searchBar.text = textView.text" and add "NSLog(@"%@",searchBar.text);"
Check in your log the value of the search bar now. You could also check your XIB file, if you have connected your search bar's delegate to your File's owner.