Skip to content

Instantly share code, notes, and snippets.

@azcoov
Created April 7, 2011 06:39
Show Gist options
  • Save azcoov/907167 to your computer and use it in GitHub Desktop.
Save azcoov/907167 to your computer and use it in GitHub Desktop.
Example of creating a UIView with MonoTouch.Dialog
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window.AddSubview (navigationController.View);
demoRoot = CreateRoot(String.Empty, String.Empty);
controller = new DialogViewController (demoRoot) {
Autorotate = true
};
navigationController.PushViewController (controller, true);
window.MakeKeyAndVisible ();
return true;
}
//MonoTouch.Dialog easy way to create a view with the elements api
RootElement CreateRoot (String lat, String lng)
{
var rootElement = new RootElement ("Location Example"){
new Section ("Latitude/Longitude data", footer){
new StyledStringElement("Latitude", lat),
new StyledStringElement ("Longitude", lng)
},
new Section() {
new StringElement ("Get location", GetLocation),
new StringElement ("Clear location", ClearLocation)
}
};
return rootElement;
}
//Get the device current location
public void GetLocation ()
{
Util.RequestLocation (newLocation => {
controller.Root = CreateRoot(newLocation.Coordinate.Latitude.ToString(), newLocation.Coordinate.Longitude.ToString());
controller.ReloadData();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment