Using becomeFirstResponder causes cancel button to not work

六眼飞鱼酱① 提交于 2019-12-13 03:43:52

问题


I have a UISearchDisplayController (searchDisplayCtr) and a UISearchBar (searchBar). I am trying to give focus to the search bar and bring up the keyboard when I click the search icon in the alphabet scroll on the right. If I include,

[self.searchDisplayCtr setActive:YES];
[self.searchDisplayCtr.searchBar becomeFirstResponder];

It brings up the keyboard and selects the search bar but the cancel button does not work consistently. I have tried resigning first responder, setting active to NO and both in searchDisplayControllerWillEndSearch, but it doesn't help. The cancel button will work only if no other letters on the alphabet scroll have been clicked yet.


回答1:


It is apparently necessary to scroll up to the top of the table before setting first responder. The code ended up being

[tableView setContentOffset:CGPointMake(0, 0) animated:NO];
[self.searchBar  becomeFirstResponder];


来源:https://stackoverflow.com/questions/21007059/using-becomefirstresponder-causes-cancel-button-to-not-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!