0
votes

I am writing on Xamarin.iOS mvvmcross app.
I saved list of viewmodelrequest whenever show a viewmodel.
Then if back button pressed, remove the last viewmodelrequest, and show previous viewmodel.

var loaderService = Mvx.Resolve<IMvxViewModelLoader>();
var viewModel = loaderService.LoadViewModel(lastRequest, null/*saved state*/);
var myVC = this.CreateViewControllerFor(viewModel) as MyViewModelView;
NavigationController.PushViewController(myVC, true); 

This works well when showing viewmodels without parameters.
But if the viewmodel has params, it shows old params.
How can show the viewmodel with latest parameter?

PS: Let me explain more detail about my situation
I have 3 touch views. View1 has an animals table, when I clicked an item on the table, app will be navigate to View2, AnimalDetailView.
When I click an edit button in the view, View3, AnimalEditView will be appeared.
There are 3 viewmodels, each of them is for each of views.
After I change and save the animal name in the View3, it is saved in AnimalEditViewModel correctly.
But when I clicked the custom back button in the View3, View2 is appeared with previous animal name.
For showing View2, I used above code.
I want to reflect latest animal name in View2.
Do you have any advice?

3

3 Answers

1
votes

I'm not quite sure what you are doing - normally navigation controllers store the view backstack for you and normally the backstack's navigation parameters don't change during a back action.

However, if you want to change the parameters during any MvxViewModelRequest, then you can access the parameters in the ParameterValues Dictionary - see code in https://github.com/MvvmCross/MvvmCross/blob/3.5/Cirrious/Cirrious.MvvmCross/ViewModels/MvxViewModelRequest.cs#L32

0
votes

There are a few ways to achieve this, but personally I would use a messenger to notify all interested VMs that the item has been updated. The VM can then decided if it needs to refresh loaded data.

In this example Stuart shows how to use a messenger to update viewmodels about location changes. The same principle applies to what you are trying to do.

0
votes

If this is about some kind of Master-Detail construction, where you update data in your Detail view (e.g. Name of an object which you want to show from a list in the master), then I would just advise to reload your data in the regular lifecycle of the page. So this would be the ViewWillAppear or the ViewDidAppear (as the ViewDidLoad does not get called in this scenario because the page had already been created).

[Edit] I missed your last remark about the update. An alternative could be to reload the page with my statement from above, while the current object can be maintained in your AppDelegate (which is available across your whole application).