当我点击 didSelectRowAtIndexPath 时,UISearchBar 中的自动更正会干扰
我有一个通常可以使用的搜索栏。当我在 iPhone 上进行测试时,问题就出现了,自动更正功能就会启动。我将搜索栏设置为如果查询栏中有文本 >长度为 4,然后开始将内容放入 searchResults 数组中。如果自动更正有建议,而我忽略它并从数组中选择某些内容,则应用程序会崩溃。我跟踪错误的事实是,在行选择之前选择了自动更正的单词(但两者都完成了),因此我认为我正在访问的 searchResults 数组不再有效。
例如,我在搜索栏中输入“demp”。自动更正建议“演示”。与此同时,搜索返回了一堆包含“dempster”的结果。我选择第一个。当我这样做时,搜索会在“演示”下重新搜索并清除原始数组(请记住,我会在服务器上进行搜索,因此数组尚未重新填充)。然后 didSelectRowAtIndexRow 方法触发,数组中没有任何内容,并且崩溃。
有什么想法吗?提前致谢。
I have a Searchbar that generally works. The problem comes when I test on the iPhone, the autocorrect kicks in. I have the search bar set that if there is text in the query bar > 4 in length,then it starts putting things into the searchResults array. If there is a suggestion from autocorrect and I ignore it and select something from the array, the app crashes. I traced the error to the fact that the autocorrected word is being selected before the row selection (but both get done), so the searchResults array I thought I was accessing is no longer valid.
For instance, I put in "demp" into the search bar. Autocorrect suggests "demo". Meanwhile, the search returns a bunch of results with "dempster" in it. I select the first. As I do this, the search re-searches under "demo" and clears the original array (keep in mind I look to a server for the searches so the array has not re-filled). Then the didSelectRowAtIndexRow method triggers and there's nothing in the array and it crashes.
Any thoughts? Thanks in Advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您使用的是搜索栏,因此不应该有自动更正,人们想要找到他们正在寻找的内容,而不是某些字典告诉他们要查找的内容。只需设置一下
,问题就迎刃而解了。
Since you are using a search bar there should be no autocorrection, people want to find what they're looking for, not what some dictionary tells them to find. Simply set
and problem will be solved.