I have the following code example to demonstrate a simple MonoTouch.Dialog table using MessageElement cells. The issue I am having is when I enable the automatic search feature in the DialogViewController. Whenever doing a search it always just displays a blank table.
If I replace the MessageElement cells with just StingElements cells the search works perfectly fine.
Does there need to be some additional code to search the MessageElement cells properly?
Any help with this issue would be greatly appreciated.
using System;
using MonoTouch.UIKit;
using MonoTouch.Dialog;
using MonoTouch.Foundation;
namespace MessageElementSearch
{
public class MessageTable : DialogViewController
{
public MessageTable(RootElement root) : base(root)
{
Section sec = new Section();
root.Add(sec);
for (int i = 0; i < 10; i++)
{
MessageElement me = new MessageElement();
me.Sender = "Sender " + i.ToString();
me.Subject = "Subject " + i.ToString();
me.Body = "Body " + i.ToString();
me.Date = DateTime.Now;
sec.Add(me);
}
this.Style = UITableViewStyle.Plain;
this.EnableSearch = true;
this.SearchPlaceholder = "Filter Table...";
}
}
}
The source code for MonoTouch.Dialog is available on github. From it you can see how
DialogViewControllerdoes it’s search (it calls theMatchesmethods on theElement) and how you can tweak it to your liking.In your case it happens that the
MessageElementtype does not overrideMatchesso it fallbacks to the the default, fromElementwhich use theCaptiondo to it’s searching.The quick fix it to inherit your own element from
MessageElement, e.g.MyMessageElement, and overrideMatchesto work as you like.