【问题标题】:MvvmCross ios UISegmentedControl to show different view controllersMvvmCross ios UISegmentedControl 显示不同的视图控制器
【发布时间】:2015-02-02 17:20:47
【问题描述】:

我需要根据在 UISegmentedControl 中选择的内容显示两个不同的视图。我真的不知道从哪里开始。视图(控制器)应显示在 UISegmentedControl 下。

所以假设我有一个包含分段控件的 MainView(Controller) 和两个视图 Child1View(Controller) 和 Child2View(Controller)

我假设我需要在 MainView(Controller) 中使用两个 MvxViewController(每个子显示一个),但我不确定当我通过分段控件选择它时如何实例化和显示它们。

我的 MainViewModel 具有显示子视图模型的命令(因为我有一个使用选项卡的等效 Android 实现),但我如何让它们显示在包含分段控件的 MainView(Controller) 中。创建我的 xib 文件时,我无法在 XCode 的 UIViewController 中放置 UIVIewController。

请帮忙。

【问题讨论】:

    标签: ios mvvmcross uisegmentedcontrol


    【解决方案1】:

    经过几个小时的尝试,这就是我所做的

    在我需要实例化的每个视图控制器的 MainView(Controller) 中,我调用了 CreateViewControllerFor 来创建我的视图控制器

    var child1ViewModelRequest = new MvxViewModelRequest(typeof(Child1ViewModel), null, null. null);
    child1View = (Child1View) this.CreateViewControllerFor<Child1ViewModel>(child1ViewModelRequest );
    

    为了显示子视图控制器,我添加了一个容器视图,它为要显示的视图控制器框住了区域,然后下面的代码显示了它

    currentViewController = (UIViewController)child1View;
    this.AddChildViewController(currentViewController);
    currentViewController.View.Frame = containerView.Bounds;
    containerView.Add(currentViewController.View);
    

    注意currentViewController和child1View是MainView(Controller)的成员变量

    【讨论】:

      猜你喜欢
      • 2013-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多