UISearchBar in UINavigationBar can't add UIBarButtonItem

青春壹個敷衍的年華 提交于 2020-01-02 16:53:39

问题


I'm trying to add a UISearchBar to a UINavigationbar using self.searchDisplayController.displaysSearchBarInNavigationBar = YES;

The UISearchBar gets added quite well into the UINavigationBar, but the left/right UIBarButtons are gone. I just can't figure out how to add them.

Andy ideas or examples on this?


回答1:


Dumb error from mine. When using self.searchDisplayController.displaysSearchBarInNavigationBar = YES; You need to use self.searchDisplayController.navigationItem to add the UIBarButtons. Now it is working properly.




回答2:


For others viewing this thread, elaborating Ben's answer is what worked for me. [self.searchDisplayController.navigationItem setLeftBarButtonItem: self.sidebarButton];



来源:https://stackoverflow.com/questions/21972759/uisearchbar-in-uinavigationbar-cant-add-uibarbuttonitem

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