Simplified UI Development with MonoTouch.SQLite
When working with iOS and MonoTouch, you may find yourself needing to display data from a SQLite table. While this can be done directly by building up your own UITableViewController, the process can be quite time consuming with quite a bit of boilerplate code. Jeffrey Stedfast has found a way to reduce simple table binding to what’s basically a single method with MonoTouch.SQLite.
MonoTouch.SQLite is a database aware UI library that is designed to make displaying table data easy. It starts with SQLiteTableModel class. Out of the box this model provides basic table access with sorting and filtering, so you don’t need to do anything with it when showing simple data. But if you need to use complex SQL, you can subclass it and override the SQL generation methods.
Next up in the stack is the controller itself. For those of you who aren’t iOS developers yet, Apple’s UI libraries require a strict adherence to the classic MVC pattern. For a table-like view, this means inheriting from the framework’s UITableViewController class. MonoTouch.SQLite handles most of the details for you via its subclass SQLiteTableViewController. In the sample application, you can see one merely has to implement the GetCell method.
End User Searching
In order to make it easier for end users to find information, MonoTouch.SQLite includes the ability to turn user entered strings into custom SQL where clauses. To do this one simply tags their data model properties with the attribute SQLiteSearchAlias. The same alias can be used multiple times, for example FirstName and LastName would probably be both tagged with the alias “name”. Then when the user types ‘address:"Newton, MA" name:Jane’ it would generate a where clause that looks for a match in the address column and either name column.
All this works with the iOS UISearchDisplayController, which is designed to wrap the aforementioned UITableViewController.
Sarah Howe Jul 06, 2015