UISearchBar implemented with Storyboards

若如初见. 提交于 2019-12-06 15:24:44

I hit this snag too with too much web information on how to do this with .xib's and no information on the newer storyboards. How I solved it was opening up the assistant editor, make sure you can see the storyboard and your view controller's .h / header file side by side.

Go to the Storyboard viewer, holding Control and click and drag the search field into the @interface area of the .h header file (yes, right into the code view). On the popup, give it a name (like 'searchBar'), it essentially creates an outlet connection in your code and should look like the following...

@interface EmployeesTableViewController : UITableViewController
    @property (weak, nonatomic) IBOutlet UISearchBar *searchBar;
@end

(It should also automatically synthesize that searchBar in the .m file, too.)

With that wired up, skipping over the UITableViewDelegate/UITableViewDataSource and File's Owner stuff via the .xib, the rest of this video tutorial http://www.youtube.com/watch?v=IqDZHgI_s24 goes into great detail on how to code the rest of the search box to filter a table view.

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