From 8a62aa867bcbc5f73775ad487ca4a61ff54f28e8 Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Sat, 15 May 2010 13:49:52 -0400 Subject: [PATCH] Add Changed event handler to the editor + Documentation updates --- MonoTouch.Dialog/DialogViewController.cs | 42 ++++++++++++++++++++++++ MonoTouch.Dialog/Elements.cs | 13 ++++++-- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/MonoTouch.Dialog/DialogViewController.cs b/MonoTouch.Dialog/DialogViewController.cs index 3adef2f9..13c8b6a2 100644 --- a/MonoTouch.Dialog/DialogViewController.cs +++ b/MonoTouch.Dialog/DialogViewController.cs @@ -25,6 +25,9 @@ public class DialogViewController : UITableViewController bool dirty; bool reloading; + /// + /// The root element displayed by the DialogViewController, the value can be changed during runtime to update the contents. + /// public RootElement Root { get { return root; @@ -42,6 +45,10 @@ public RootElement Root { } EventHandler refreshRequested; + /// + /// If you assign a handler to this event before the view is shown, the + /// DialogViewController will have support for pull-to-refresh UI. + /// public event EventHandler RefreshRequested { add { if (tableView != null) @@ -53,6 +60,14 @@ public event EventHandler RefreshRequested { } } + /// + /// Invoke this method to trigger a data refresh. + /// + /// + /// This will invoke the RerfeshRequested event handler, the code attached to it + /// should start the background operation to fetch the data and when it completes + /// it should call ReloadComplete to restore the control state. + /// public void TriggerRefresh () { if (refreshRequested == null) @@ -74,6 +89,9 @@ public void TriggerRefresh () } } + /// + /// Invoke this method to signal that a reload has completed, this will update the UI accordingly. + /// public void ReloadComplete () { if (refreshView != null) @@ -94,6 +112,9 @@ public void ReloadComplete () UIView.CommitAnimations (); } + /// + /// Controls whether the DialogViewController should auto rotate + /// public bool Autorotate { get; set; } public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation) @@ -240,6 +261,12 @@ public override float GetHeightForRow (UITableView tableView, MonoTouch.Foundati } } + /// + /// Activates a nested view controller from the DialogViewController. + /// If the view controller is hosted in a UINavigationController it + /// will push the result. Otherwise it will show it as a modal + /// dialog + /// public void ActivateController (UIViewController controller) { dirty = true; @@ -254,6 +281,21 @@ public void ActivateController (UIViewController controller) PresentModalViewController (controller, true); } + /// + /// Dismisses the view controller. It either pops or dismisses + /// based on the kind of container we are hosted in. + /// + public void DeactivateController (bool animated) + { + var parent = ParentViewController; + var nav = parent as UINavigationController; + + if (nav != null) + nav.PopViewControllerAnimated (animated); + else + DismissModalViewControllerAnimated (animated); + } + public override void LoadView () { tableView = new UITableView (UIScreen.MainScreen.Bounds, Style) { diff --git a/MonoTouch.Dialog/Elements.cs b/MonoTouch.Dialog/Elements.cs index f2a1efca..5dda6783 100644 --- a/MonoTouch.Dialog/Elements.cs +++ b/MonoTouch.Dialog/Elements.cs @@ -872,8 +872,8 @@ public class EntryElement : Element { UITextField entry; string placeholder; static UIFont font = UIFont.BoldSystemFontOfSize (17); - - public Func Validator; + + public event EventHandler Changed; /// /// Constructs an EntryElement with the given caption, placeholder and initial value. @@ -1006,7 +1006,14 @@ public override UITableViewCell GetCell (UITableView tv) public void FetchValue () { - Value = entry.Text; + var newValue = entry.Text; + var diff = newValue != Value; + Value = newValue; + + if (diff){ + if (Changed != null) + Changed (this, EventArgs.Empty); + } } protected override void Dispose (bool disposing)