MvvmCross iOS presenter IMvxTouchView.ViewModel is null -
i working on project involves mvvmcross. ios, use custom presenter inherits mvxtouchviewpresenter.
public override void show(imvxtouchview view) { var viewcontroller = view uiviewcontroller; if (viewcontroller == null) throw new mvxexception("passed in imvxtouchview not uiviewcontroller"); if (_masternavigationcontroller == null) showfirstview(viewcontroller); else _masternavigationcontroller.pushviewcontroller(viewcontroller, true /*animated*/); var myviewmodel = view.viewmodel; //do staff myviewmodel } my problem in cases myviewmodel null @ moment. created later on ... when viewcontroller loaded. looks timing problem... interesting fact code worked @ previous mvvmcross project.
i tried use :
var myviewmodel = view.reflectiongetviewmodel (); unfortunately result same :( having idea how fix or work around problem ?
mvvmcross creates viewmodel part of base.viewdidload() within viewcontroller - if viewdidload has not been called there won't viewmodel yet.
based on this:
you try trigger
viewloaded - causeviewdidloadfire? (the easiest way try referenceview).or trick mvvmcross loading
viewmodellittle bit - this, callonviewcreateextension method https://github.com/mvvmcross/mvvmcross/blob/v3.1/cirrious/cirrious.mvvmcross.touch/views/mvxviewcontrollerextensionmethods.cs#l18
Comments
Post a Comment