搜索栏委托 - searchBarShouldBeginEditing / searchBarTextDidBeginEditing 之间的区别?

发布于 2024-08-11 09:54:14 字数 278 浏览 4 评论 0原文

他们之间有什么区别?在我的实验中,一旦用户点击搜索栏调出键盘,它们似乎会在同一操作中被调用。尽管用户尚未编辑实际文本,但仍然如此。这似乎调用了searchBar:textDidChange。但每次改变都会被要求,而不仅仅是一开始一次。这意味着我必须编写更多代码来复制搜索栏在 Google 地图中的行为方式。

好吧,所以这更多地变成了发泄——但也许我错过了一些东西。是否存在调用 searchBarShouldBeginEditing 但不调用 searchBarTextDidBeginEditing 的情况 - 反之亦然?

What's the difference between them? In my experimentation, they seem to get called during the same action - once the user taps the search bar to bring up the keyboard. This is despite the user not having editing the actual text yet. Which seems to call searchBar:textDidChange. But that gets called for each change, not just once at the beginning. Which means I have to write more code to duplicate how the Search Bar behaves in Google Maps.

OK, so that turned more into venting - but maybe I'm missing something. Are there cases in which searchBarShouldBeginEditing is called but not searchBarTextDidBeginEditing - or vice-versa?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

女中豪杰 2024-08-18 09:54:14

任何名称中带有“should”的消息都应该返回一个布尔值。如果这是错误的,那么在这种情况下,编辑不会开始,并且搜索栏不会成为FirstResponder(即,用户点击它,但不会出现用于编辑的键盘)。

Any message with "should" in the name is expected to return a boolean. If that's false, then, in this case, editing is not begun, and the search bar does not becomeFirstResponder (ie, the user taps on it, but no keyboard appears for editing).

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