首页 \ 问答 \ Mvvmcross - 容器UIViewController(Mvvmcross - Container UIViewController)

Mvvmcross - 容器UIViewController(Mvvmcross - Container UIViewController)

我正在尝试实现一个Custom UIViewController类,它将充当我的导航控制器,而不是使用默认的导航控制器。 下面是我的容器类:

enter code here public partial class ContainerView:MvxViewController {static bool UserInterfaceIdiomIsPhone {get {return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; }}

    private UIViewController _currentView;

    protected ContainerViewModel ContainerModel
    { get { return base.ViewModel as ContainerViewModel; } }

    public ContainerView ()
        : base (UserInterfaceIdiomIsPhone ? "ContainerView_iPhone" : "ContainerView_iPad", null)
    {

    }



    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();

        var loginView = this.CreateViewControllerFor(ContainerModel.Login) as UIViewController;
        ShowViewController(loginView);
        // Perform any additional setup after loading the view, typically from a nib.
    }

    public ContainerView(UIViewController controller)
        : base(UserInterfaceIdiomIsPhone ? "ContainerView_iPhone" : "ContainerView_iPad", null)
    {
        ShowViewController(controller);
    }

    public void ShowViewController(UIViewController viewController)
    {
        if (_currentView !=null)
        {
            RemoveCurrentViewController();
        }

        AddChildViewController(viewController);
        viewController.View.Frame = GetViewFrame();
        containerView.AddSubview(viewController.View);
        _currentView = viewController;
        viewController.DidMoveToParentViewController(this);

    }

    public void RemoveCurrentViewController()
    {
        _currentView.WillMoveToParentViewController(null);
        _currentView.View.RemoveFromSuperview();
        _currentView.RemoveFromParentViewController();

    }

    public RectangleF GetViewFrame()
    {
        return containerView.Bounds;
    }
}

我的第一次加载很好,因为登录视图被加载到containerView中,这是一个来自笔尖的插座。 问题是随后的请求我的插座是空的。 我可能做错了,但我试图在Presenter Show方法中设置viewcontroller,如下所示:

public class MyPresenter: MvxTouchViewPresenter
    {
        private static ContainerView _cv;

        public BlackhawkPresenter(MvxApplicationDelegate appDelegate, UIWindow window)
            : base(appDelegate, window)
        {
            _cv = new ContainerView();
            window.RootViewController = _cv;
        }

        protected override UINavigationController CreateNavigationController(UIViewController viewController)
        {
            return new BlackhawkNavigationController(viewController);
        }

        public override void Show(Cirrious.MvvmCross.ViewModels.MvxViewModelRequest request)
        {
            var viewController = (UIViewController)Mvx.Resolve<IMvxTouchViewCreator>().CreateView(request);
            if(request.ViewModelType == typeof(ContainerViewModel))
                base.Show(request);
            else
                _cv.ShowViewController(viewController);

        }

    }

对于show中的else语句,因为“ViewDidLoad”从不触发我的插座是null。 我不确定是否有任何阻止ShowViewModel将其显示在容器类容器View中的调用。


I am trying to implement a Custom UIViewController class that will act as my navigation controller rather than using the default navigation controller. Below is my container class I have:

enter code herepublic partial class ContainerView : MvxViewController { static bool UserInterfaceIdiomIsPhone { get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; } }

    private UIViewController _currentView;

    protected ContainerViewModel ContainerModel
    { get { return base.ViewModel as ContainerViewModel; } }

    public ContainerView ()
        : base (UserInterfaceIdiomIsPhone ? "ContainerView_iPhone" : "ContainerView_iPad", null)
    {

    }



    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();

        var loginView = this.CreateViewControllerFor(ContainerModel.Login) as UIViewController;
        ShowViewController(loginView);
        // Perform any additional setup after loading the view, typically from a nib.
    }

    public ContainerView(UIViewController controller)
        : base(UserInterfaceIdiomIsPhone ? "ContainerView_iPhone" : "ContainerView_iPad", null)
    {
        ShowViewController(controller);
    }

    public void ShowViewController(UIViewController viewController)
    {
        if (_currentView !=null)
        {
            RemoveCurrentViewController();
        }

        AddChildViewController(viewController);
        viewController.View.Frame = GetViewFrame();
        containerView.AddSubview(viewController.View);
        _currentView = viewController;
        viewController.DidMoveToParentViewController(this);

    }

    public void RemoveCurrentViewController()
    {
        _currentView.WillMoveToParentViewController(null);
        _currentView.View.RemoveFromSuperview();
        _currentView.RemoveFromParentViewController();

    }

    public RectangleF GetViewFrame()
    {
        return containerView.Bounds;
    }
}

My first load is fine as the login view is loaded into the containerView which is an outlet from the nib. The problem is on subsequent request my outlet is null. I may be doing this wrong but I am attempting to set the viewcontroller in the Presenter Show method as per below:

public class MyPresenter: MvxTouchViewPresenter
    {
        private static ContainerView _cv;

        public BlackhawkPresenter(MvxApplicationDelegate appDelegate, UIWindow window)
            : base(appDelegate, window)
        {
            _cv = new ContainerView();
            window.RootViewController = _cv;
        }

        protected override UINavigationController CreateNavigationController(UIViewController viewController)
        {
            return new BlackhawkNavigationController(viewController);
        }

        public override void Show(Cirrious.MvvmCross.ViewModels.MvxViewModelRequest request)
        {
            var viewController = (UIViewController)Mvx.Resolve<IMvxTouchViewCreator>().CreateView(request);
            if(request.ViewModelType == typeof(ContainerViewModel))
                base.Show(request);
            else
                _cv.ShowViewController(viewController);

        }

    }

for the else statement in the show as the "ViewDidLoad" never fires my outlet is null. I am not sure of any othe rway to intercept the call for ShowViewModel to display it in container View in my container class.


原文:https://stackoverflow.com/questions/21806826
更新时间:2023-07-02 18:07

最满意答案

你有一个自引用表。 这并不全是坏事。 你所要做的就是创建一个像这样的查询。

SELECT * FROM content where subcontentID = contentID AND contentID = @contentID

结果将是具有指定contentID的所有内容记录

如果您也需要查看所有数据,则有序的结果集可能会更好。

SELECT * FROM content where subcontentID = contentID ORDER BY subcontentID,contentID

这将为您提供所有内容记录,将所有子内容记录保存在一起。

这完全没有问题,它可以避免使用相同的模式创建重复的表。


You have a self referencing table. This isn't all bad. All you have to do is create a query like this.

SELECT * FROM content where subcontentID = contentID AND contentID = @contentID

The results will be all the content records that have the specified contentID

An ordered result set might be nice if you need to see all the data too.

SELECT * FROM content where subcontentID = contentID ORDER BY subcontentID,contentID

This will give you all the content records keeping all the subcontent records together in order.

This is not bad at all it saves from creating a duplicate table with the same schema.

相关问答

更多
  • preg_match("/\[(.+)\]/",$string,$matches); echo $matches[1]; preg_match("/\[(.+)\]/",$string,$matches); echo $matches[1];
  • 经过几个小时的解析自己很多网站后,我找到了一些东西: JE.ValById("#code") - 返回textarea或任何输入的值 JsCmds.SetValById("#code", "test value") - 将vlaue设置为找到的元素 After some hours of parsing myself a lot of sites, i found something : JE.ValById("#code") - returns value of textarea or any input ...
  • 你有一个自引用表。 这并不全是坏事。 你所要做的就是创建一个像这样的查询。 SELECT * FROM content where subcontentID = contentID AND contentID = @contentID 结果将是具有指定contentID的所有内容记录 如果您也需要查看所有数据,则有序的结果集可能会更好。 SELECT * FROM content where subcontentID = contentID ORDER BY subcontentID,contentID ...
  • 当您需要使用不间断的空间时,就是这种情况  。 如果是HTML内容,那么您可以使用 World 。 然而,你需要使用unicode编码形式的U+00A0 :before ,它看起来像这样: p#content { border: 1px solid black; padding: 5px; width: 65px; } a.textLink:before { content: ...
  • 没有任何代码,很难确定你的问题是什么。 但是,听起来你混淆了视图和模型之间的行索引。 当您有行号时,您必须非常清楚您所指的坐标系统(视图或模型)。 有关convertRowIndexToModel和convertRowIndexToView方法,请参阅JTable API 。 你可能需要这样的东西: JTable table = ...; TableModel model = ...; int viewRow = table.getSelectedRow(); int modelRow = table.c ...
  • 我还就此问题向供应商提出了支持电话。 事实证明,Valence API版本<= 1.4中的错误是由包含主题文件的模块触发的,该主题文件以点/句点结束(因此,一旦给定扩展名,其形式为some_file..ext )。 解决方案:升级到修复错误的Valence 1.6,或重命名受影响的文件。 I also raised a support call with the vendor for this issue. It turns out to be a bug in Valence API versions < ...
  • 由于安全性限制,您无法跨域(/ ports / protocols)直接与正文中的其他元素通信。 您不仅无法访问目标文档源,也无法访问对象和事件。 您可以做的是使用框架通过代理跨域发送消息。 这个答案谈到了这一点。 You can not directly communicate with other elements in the body across domains (/ports/protocols) due to security constraints. Not only can't you a ...
  • 您需要执行http get请求 import urllib2 link = "http://whatever.com/your-file.js" urllib2.urlopen(link).read() php代码正在使用curl,它比它看起来做的更多 You need to do a http get request import urllib2 link = "http://whatever.com/your-file.js" urllib2.urlopen(link).read() The php ...
  • 您可以使用表集合表达式 : table_collection_expression允许您通知Oracle,应将collection_expression的值视为表,以便进行查询和DML操作。 collection_expression可以是子查询,列,函数或集合构造函数。 无论其形式如何,它都必须返回一个集合值 - 即类型为嵌套表或varray的值。 提取集合元素的过程称为集合取消。 因此,在您的情况下,当您的函数返回嵌套表类型时,您可以执行以下操作: select * from table(exportF ...
  • saveData不返回任何内容,不返回文件名 filename = saveData(members) loadData不返回文件名,它返回成员。 filename = loadData() 我建议研究全局变量如何在Python中工作。 您只需要一个members实例。 如果您正在寻找更好的方法来执行CRUD操作,请使用Python的sqlite模块 顺便说一句,Pycharm有一个有用的调试器。 saveData returns nothing, not the filename filename = ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)