[MonoTouch] UITableViews made simple

Miguel de Icaza miguel at novell.com
Sat Nov 14 01:28:52 EST 2009


Hey folks,

    I have been thinking about writing a control that would simplify
making configuration-like UITableView, and I am struggling between the
Mono.Options-like model for creating the data to be debugged and a setup
with classes and attributes.

    For example, this is what the code would look like using classes and
attributes, it would use Reflection over public field names to extract
default captions and attributes to spice up the UI (icons, separators,
parameters).

    Another option would be to build it like Mono.Options, where the UI
is constructed one item at a time and would be trivial to add event
handlers that respond on changes (with delegates):

Style 1:

class SoundConfig : Configurable {
	[Icon ("airplane.png")]
	public bool AirplaneMode;

	[Text ("Wi-Fi"), Icon ("wifi.png")]
	public Configurable WiFi;

	[Icon ("Notifications")]
	public Configurable Notifications;

	[Icon ("Silent.png")]
	public Separator Silent;
	public bool Vibrate;

	[Icon ("Ring")]
	public Separator Ring;
	public bool on;

	[Slider ("mute.png", "full-volume.png")]
	public float value;
}

UIViewController Do ()
{
	var s = new SoundConfig () {
		AirplaneMode = true,
		WiFi = ...;
		Notifications = ...;
		Vibrate = true;
		on = false;
		value = -0.5;
	}			
	return new ReflectionViewController (s);
}


Style 2:
class Demo {
	static bool airplane;
	static string wi_fi;
	
	void Setup ()
	{
		
		var settings = new SettingsViewController (){
			{ airplane_icon, airplane, "Airplane Mode", v => airplane = v },
			{ wifi_icon, wi_fi, "Wi-Fi", r => return r.ToString () }
		};			

		
	}
	
}



More information about the MonoTouch mailing list