Reputation: 581
I currently have an app that contains a list of items, I now want to be able to search that list. I know Ill need to use a Search Bar and Controller, the only thing is, I can't find any documentation or examples for implementing this. I have a controller class setup for the search bar, but its a blank class. Where is a good starting point for this?
This question seems to be a good spot, but where does that go, and how do I port that to C# for xamarin?
Upvotes: 1
Views: 5674
Reputation: 14294
Xamarin 5.10:
var sampleSearchBar = new UISearchBar (new CoreGraphics.CGRect (20, 20, this.View.Frame.Width - 50, 40));
sampleSearchBar.SearchBarStyle = UISearchBarStyle.Prominent;
sampleSearchBar.ShowsCancelButton = true;
//Deleagte class source
sampleSearchBar.Delegate = new SearchDelegate ();
this.View.AddSubview (sampleSearchBar);
Add Delegate class to the ViewController.
class SearchDelegate : UISearchBarDelegate
{
public override void SearchButtonClicked (UISearchBar bar)
{
bar.ResignFirstResponder ();
}
public override void CancelButtonClicked (UISearchBar bar)
{
bar.ResignFirstResponder ();
}
public override bool ShouldBeginEditing (UISearchBar searchBar)
{
return true;
}
public override bool ShouldEndEditing (UISearchBar searchBar)
{
return true;
}
public override bool ShouldChangeTextInRange (UISearchBar searchBar, NSRange range, string text)
{
Console.WriteLine (searchBar.Text);
return true;
}
}
Upvotes: 3
Reputation: 477
I create this demo for you with Storyboard and UISearchDisplayControlelr.
Look at this SearchDemo.
Upvotes: 1
Reputation: 8965
This is an iOS sample application that demonstrates how to use UISearchController. A search controller manages the presentation of a search bar (in concert with the results view controller’s content) Look at this and let me know if any issue after that. https://github.com/xamarin/monotouch-samples/tree/master/ios8/TableSearch
Upvotes: 1