UIPicker in the iPhone with MonoTouch - More Wally - Wallace B. McClure
in

MoreWally.com

Giving people what they want, More Wally. This is the technical and personal blog site of
Wallace B. (Wally) McClure.

This Blog

Syndication

News

Please goy buy 3-4 copies of my book on MonoTouch titled "Professional Android Programming with Mono for Android for .NET/C# Developers." They make great gifts all year round. Plus, I get about $.25 when you buy a copy.

Technical Sites

More Wally - Wallace B. McClure

This blog will have all kinds of posts about Wally McClure. In it, there will be tons of .NET and computer programming posts as well as Wally's views on life in general. As you might guess, this site and blog help you get More Wally in your life. What more could anyone want? iPhone, Android, MonoTouch, MonoDroid, Mobile, HTML5, .NET, ADO.NET, ASP.NET, AJAX, jQuery, jQuery Mobile, ASP.NET AJAX, and Windows Azure............follow me on twitter at Wally

UIPicker in the iPhone with MonoTouch

 UIPicker

The UIPicker is visually different than the drop down listbox that most .NET developers are familiar, however, it is designed to perform the same type of function.  It allows users to select from a fixed set of data isntead of typing in data in a text box.  Programming with it is fairly simple.  Inherit from the UIPickerViewModel class and then bind the data.

Here's the class:

using System;using MonoTouch;using MonoTouch.UIKit;using MonoTouch.Foundation; namespace OpenUrl{  public class ProtocolData : UIPickerViewModel{ public static string[] protocols = new string[]{"http://", "tel:","http://maps.google.com/maps?q=", "sms:","mailto:"};public string[] protocolNames = new string[]{"Web", "Phone Call", "Google Maps", "SMS", "Email"     };AppDelegate ad;public ProtocolData(AppDelegate pad){ad = pad;}public override int GetComponentCount(UIPickerView uipv){return(1);}public override int GetRowsInComponent( UIPickerView uipv, int comp){//each component has its own count.int rows = protocols.Length;return(rows);}public override string GetTitle(UIPickerView uipv, int row, int comp){//each component would get its own title.string output = protocolNames[row];return(output);}public override void Selected(UIPickerView uipv, int row, int comp){ad.SelectedRow = row;}public override float GetComponentWidth(UIPickerView uipv, int comp){return(300f); }public override float GetRowHeight(UIPickerView uipv, int comp){return(40f);  }}}

And then you bind data doing something like this:

ProtocolData protocolDataSource = new ProtocolData(this);ProtocolSelection.Model = protocolDataSource;And there you go, you now have a UIPicker with a list of data.

Want to know more about developing with the iPhone?  Check out my Wrox Blox eBook on developing applications with MonoTouch for the iPhone/iPod touch for .NET/C# developers

Comments

 

Twitter Trackbacks for UIPicker in the iPhone with MonoTouch - More Wally - Wallace B. McClure [morewally.com] on Topsy.com said:

Pingback from  Twitter Trackbacks for                 UIPicker in the iPhone with MonoTouch - More Wally - Wallace B. McClure         [morewally.com]        on Topsy.com

December 31, 2009 9:00 AM
 

MonoTouch.Info said:

Thank you for submitting this entry - Trackback from MonoTouch.Info

December 31, 2009 11:26 AM
2006 - Wallace B. McClure
Powered by Community Server (Non-Commercial Edition), by Telligent Systems