DialogViewController不会触发ViewDidDisappear

时间:2012-12-08 15:49:49

标签: xamarin.ios monotouch.dialog

我有如下的层次结构:

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);
    }
}

1 个答案:

答案 0 :(得分:2)

这不是如何使用UINavigationControllerDialogViewController。 记住UIViewController的基本概念:一个控制器处理屏幕上的内容(在iPhone上)。这意味着,您应该在UIViewController's堆栈上推送控制器。每个控制器都可以是DialogViewControllers。 说到这一点,你已经可以看到在MeasurementViewModel部分中添加WorkoutsView的视图(Root)是上述概念的一个突破,因此,你违反了Apple的设计规则和结果:你的<{1}}方法不会被调用。

相反:在元素上添加一个回调,其中一个可以在导航控制器的堆栈上推送一个新的控制器。

您应该能够在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/