Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News MonoTouch.Dialog Makes Creating Simple iPhone Dialogs Easier and Faster

MonoTouch.Dialog Makes Creating Simple iPhone Dialogs Easier and Faster

This item in japanese

In order to simplify iPhone development using MonoTouch, Miguel de Icaza has developed two new abstraction layers over UITableView. These abstraction layers give developers the option to use a declarative syntax based on attributes or an imperative model based on nested controls.

UITableView or “table view” is the workhorse for iPhone development. While quite powerful, it can also be tedious to use. One cannot simply add new sections and rows. First, one has to override the numberOfSections function to return the correct count. Then the numberOfRowsInSection function must be adjusted to return the correct value for each function. Finally the widget itself can be loaded via the cellForRowAtIndexPath function. If these three functions are not kept in sync, the UI could look as if it were randomized.

The first of Miguel’s abstraction layers uses a series of nested “elements”. Each element represents a type of widget that will be placed into a cell at runtime. Here is an example from Miguel’s blog.

  var root = new RootElement ("Settings") { 
          new Section (){ 
              new BooleanElement ("Airplane Mode", false), 
              new RootElement ("Notifications", 0, 0) { Notifications } 
          new Section (){ 
              new RootElement ("Sound"), { Sound }, 
              new RootElement ("Brightness"){ Brightness }, 
              new RootElement ("Wallpaper"){ Wallpaper } 
          new Section () { 
              new EntryElement ("Login", "Your login name", "miguel"), 
              new EntryElement ("Password", "Your password", "password", true), 
              new DateElement ("Select Date", DateTime.Now), 
              new TimeElement ("Select Time", DateTime.Now)

Miguel writes,

Although the UITableView is built on the powerful Model/View/Controller setup that would allow it to scale efficiently to large data sets, most configuration pages and data entry pages do not require this complexity.

Another feature is that it takes care of all the bookkeeping required to do text entry without any work from the programmer: accepting keyboard input, automatically switching to the next entry line on return, aligning all entry lines in a section, dismissing the keyboard with the last input is reached.

Miguel is also offering a reflection based design for quick and dirty configuration screens. This technique relies on the compiler compiling the member variables in the same order as they are found in source code, so be wary of code formatting utilities that automatically sort your code.

  class AccountInfo { 

  public bool AirplaneMode; 

  [Section ("Data Entry", "Your credentials")] 

  [Entry ("Enter your login name")] 
  public string Login; 

  [Caption ("Password"), Password ("Enter your password")] 
  public string passwd; 

  [Section ("Travel options")] 
  public SeatPreference preference; 

MonoTouch.Dialog is being offered under the MIT X11 license. MonoTouch itself is a commercial product from Novell that allows .NET based applications to run on Apple’s iPhone and iPad devices.

Rate this Article