2012-12-08 77 views
0

我有類似下面的層次結構:DialogViewController沒有發射ViewDidDisappear

NavigationController 
  • 推第一ViewController - ViewDidDisappear火災正確去下一個視圖

  • DialogViewController,有一個列表時 - ViewDidDisappear接下來會發生火災

  • 每個列表都會打開一個新的DialogViewController - ViewDidDisappear從來文件

  • 上有此一說打開另一個DialogViewController一些按鈕 - VidDidDisappear永遠不會觸發

代碼:

public partial class CustomDialogController : DialogViewController { 

    public CustomDialogController() : base (UITableViewStyle.Grouped, null, true) { 
    } 

    public override void ViewDidDisappear (bool animated) 
    { 
     base.ViewDidDisappear (animated); 
     Console.WriteLine("Gone baby 2"); 
     // Never Fires 
    } 
    } 

public partial class WorkoutsView : DialogViewController 
{ 

    public override void ViewDidDisappear (bool animated) 
    { 
     base.ViewDidDisappear (animated); 
     Console.WriteLine("Gone baby"); 
     // Here is where you can add your custom code for when the DialogViewController disappears 
    } 


    public WorkoutsView (MetaFitness.BL.MetaFitnessManager manager) : base (UITableViewStyle.Grouped, null, true) 
    { 
     this.Title ="Title"; 
     WorkoutViewModel WorkoutDetail = new WorkoutViewModel(); 
     //var bc = new BindingContext (this, WorkoutDetail, "Details"); 
     //detailView = new DialogViewController(bc.Root,true); 
     List<Workout> workouts = manager.GetWorkouts(); 

     var abc = new CustomDialogController(); 
     abc.Root = new RootElement("WorkoutsView"); 
     Root = abc.Root; 
     Section section = new Section ("Workouts"); 
     foreach (var wo in workouts) { 
      string name = string.Empty; 

      CustomDialogController WorkoutController = new CustomDialogController(); 
      WorkoutController.Root = new RootElement(wo.Name); 
      RootElement wSection = WorkoutController.Root; 

      var s2 = new Section(); 
      var mvm2 = new MeasurementViewModel(); 
          // the code for this is similar to CustomDialogController - never fires 
      s2.Add(new MeasurementViewController(mvm2).Root); 
      wSection.Add (s2); 


      section.Add(wSection); 

     } 
     Root.Add(section); 
    } 
} 

回答

2

這不是如何使用UINavigationControllerDialogViewController。 記住UIViewController的基本概念:一個控制器處理屏幕上的內容(在iPhone上)。這意味着,您應該推動控制器在UIViewController's堆棧上。這些控制器中的每一個都可以是DialogViewControllers。 說完這個,你已經可以看到在WorkoutsView的區域內添加MeasurementViewModel的視圖(Root)是上述概念的一個突破,因此,你違反了Apple的設計規則和結果:你的View*()方法將不會被調用。

改爲:在您的元素上添加回調,其中一個可以在導航控制器的堆棧上推送新的控制器。

你應該能夠找到MT.Dialog的Github上頁的所有必要的文件:https://github.com/migueldeicaza/MonoTouch.Dialog或Xamarin博客:http://blog.xamarin.com/2012/02/10/easily-create-ios-user-interfaces-with-monotouch-dialog/

+0

謝謝,讓我直。 – lucuma