2012-04-12 7 views
0

私は2つの "入れ子になった" DialogViewControllerを持っています - "View"と "Edit"。両方ともStringElementsを使用して内部データ構造からデータをレンダリングします。 Edit DVCでは、内部データ構造を更新するためにStringElementのChangedイベントをフックします。また、編集DVCのViewDissapearing(sic)イベントをフックして、View DVCを再レンダリングし、編集内容をクラウドサービスに送信します。MonoTouch.Dialogでイベントを発生させるEventHandlerの順序を制御できますか?

私の問題は、変更されたイベントハンドラがViewDissapearingイベントハンドラの後に呼び出されますので、私の内部データ構造は、時間内に更新されないということです。

次のようなものになりますDVCの設定コード:

var root = RenderViewItem(ThisItem);    
    var dvc = new DialogViewController(root, true); 

    // create an Edit button which pushes the edit view onto the nav stack 
    dvc.NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Edit, delegate { 
     var editRoot = RenderEditItem(ThisItem, true /* render the list field */); 
     editViewController = new DialogViewController(editRoot, true); 
     editViewController.ViewDissapearing += (sender, e) => 
     { 
      // trigger a sync with the service when the view disappears      
      App.ViewModel.SyncWithService(); 

      // reload the View page 
      dvc.BeginInvokeOnMainThread(() => 
      { 
       var oldroot = root; 
       root = RenderViewItem(ThisItem); 
       dvc.Root = root; 
       dvc.ReloadData(); 
       oldroot.Dispose(); 
      }); 
     };  
     controller.PushViewController(editViewController, true); 
    }); 

    // push the "view item" view onto the nav stack 
    controller.PushViewController(dvc, true); 

インサイドRenderEditItemを()、私は内部データ構造に基づいてStringElementsを追加し、通常の方法で変更されたイベントハンドラを追加します。

stringElement.Changed += delegate { /* change a data structure */ }; 

ChangedイベントハンドラがViewDissapearingイベントハンドラの前に火災に取得する方法はありますか?

+0

、私の回避策はNSTimer.CreateScheduledTimer(0.5、デリゲート{})で私ViewDissapearingイベントハンドラのコードをラップすることです。それは醜いですが、私が求めている行動を得るために見つけた唯一の方法です... –

答えて

0

いいニュースです! MonoTouch.Dialogバージョン5.2.11では、EntryElement.Changedイベントの発生方法が変更されました。フォーカスの変更が発生した場合にのみ、キーストロークごとに発生します。私の "競合状態"はもはや発生しなくなり、NSTimerのハックを解消することができました。

この変更に関連する利点は、もはやEntryElement.Valueが最新であることを保証するためにEntryElement.FetchValue()を呼び出す必要がないということです。詳細は

http://docs.xamarin.com/ios/releases/MonoTouch_5/MonoTouch_5.2#11。今

関連する問題