调用 searchBarSearchButtonClicked 时,SearchBar 文本为空

发布于 2024-11-19 10:26:50 字数 272 浏览 4 评论 0原文

我已经在视图控制器中实现了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滿滿的愛 2024-11-26 10:26:50

您应该使用“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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文