In my previous post I wrote about persisting a UISearchBar value so it would be available when pushing the user a new View Controller to display the Search Results. My app has a simple SearchResults UIViewController where some UILabels are populated with various result attributes.
Interestingly, the UILabel(s) and other controls maintain their original result values when clicking the back button and searching again for a different Ticket. I wasn’t expecting this, my expectation was that if I pushed another search through and repopulated the labels that the new results would appear.
For now, the only way I’ve been able to accomplish this is to null the SearchResults View Controller and new it up again when the Search Button is clicked. It works but it seems kludgy, hopefully someone can enlighten me on this with their experience?
this.txtSearch.SearchButtonClicked += (sender, e) => {
// Populate the Search Criteria Property so it can be accessed from another view controller
searchCriteria = txtSearch.Text;
// Clear entered value
txtSearch.Text = string.Empty;
// insures that the search results view controller isn’t maintaining the previous search results.
_searchResultsViewController = null; // <– null the vc to drop previously populated results/kludgy
// new up Search Results View Controller
if (this._searchResultsViewController == null) {
this._searchResultsViewController = new searchResults ();
}
// send user to search results view controller
this.NavigationController.PushViewController (this._searchResultsViewController, true);
} ;
Vic, this, and your previous post on the topic, are terrific. I’m struggling to do something similar and am having a frustratingly harder-than-expected time of it. Any chance you could post the full source code to this? Or at least the full code for the methods related to the search bar functionality?
Sure, i’ll post a complete example.