I need a search control that allows a user to search for something, then if they don't find it they push an add button to add it. I need the add button to display while the user is typing the text to search for, I'm thinking to the right of the text. If I put the button in the navigation bar, it doesn't display while the user is searching.
I want to use a Search Bar and Search Display Controller as I need the functionality of displaying results as the user types. The first answer here -- Adding button to left of UISearchBar -- doesn't seem to work with the Search Display Controller. When the user activates the search field, it disappears.
I have been down several rabbit trails on this:
In the second answer here -- Adding button to left of UISearchBar -- I see it recommended to override the Bookmarks button. That is very clever and works, but I can't figure out how to get the "official" Add button image to override with. The simulator doesn't seem to have the images anymore (?), and I don't like the idea of hardcoding something in my code anyway. I'd rather (re)use Apple's Add button icon, but I can't figure out how to do that.
I played around with creating a subclass of UISearchBar that is loaded from a nib that has the search bar and the button, but I'm realizing if I go down that path I think I have to reimplement the interface for UISearchBar and forward all of the method calls to the "real" UISearchBar that I am managing. That seems gross.
I tried just creating a view that subclasses UISearchBar and just dynamically adds the button at initialization time. But on that path I am very bogged down in the constraints. The constraints for the text field in the search bar are up a couple of levels in the view hierarchy, and I'm pretty sure there is at least one constraint up there that I will need to remove, agreed? (because the text field is currently constrained to extend to the end of the search bar).
I also tried the same subclass and trying to just set the positions of the controls in layoutSubviews, but when I do that I find myself having to position all the child controls in the search bar (including the Cancel button, etc.), and that seems wrong.
I'm still in learning mode, and I'm not on a tight schedule. I would like to do this the "right" way. Meaning I'd like to reuse existing code and functionality and just add an add button. What is the "right" way to approach this?
Thanks!