搜索栏委托 - searchBarShouldBeginEditing / searchBarTextDidBeginEditing 之间的区别?
他们之间有什么区别?在我的实验中,一旦用户点击搜索栏调出键盘,它们似乎会在同一操作中被调用。尽管用户尚未编辑实际文本,但仍然如此。这似乎调用了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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
任何名称中带有“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).