5

I have my ViewController like

public partial class TestView
        : MvxViewController
{
...code here...
}

and i load my next ViewController on button event TouchUpInside like that:

btnSearch.TouchUpInside  += (object sender, EventArgs e) => {
        BTProgressHUD.Show("test");
        ViewModel.GoParameterizedCommand.Execute(null);
    };

that event it's defined in ViewDidLoad. My "test" message it's showed on next ViewController and not during loading of this one. How could i show that message during loading and not when next ViewController is loaded? I have tried to use also MBProgressHUD

btnSearch.TouchUpInside  += (object sender, EventArgs e) => {
        var hud = new MTMBProgressHUD (View) {
            LabelText = "Waiting...",
            RemoveFromSuperViewOnHide = true
        };


        View.AddSubview(hud);
        hud.Show (animated: true);

        ViewModel.GoParameterizedCommand.Execute(null);
    };

but behaviour it's same.

Luigi Saggese
  • 5,299
  • 3
  • 43
  • 94

3 Answers3

2

It seems that you are trying to work with ProgressHUD in View layer. In MVVM-way you should create a "Loading" property in your ViewModel and bind it to progressbar in View.

Here is a good Stuart's video how to do that: http://youtu.be/6fNXGErr9to

And here is sample code: https://github.com/MvvmCross/NPlus1DaysOfMvvmCross/tree/master/N-34-Progress

olexa.le
  • 1,697
  • 10
  • 14
  • That seems to be a workaround not a solution. I have tested it. I have set a property on my ViemModel when it's invoked execute command (as like in github posted by you). Property and progressHud are right set. Problem is that waiting pop up it's not showed during loading but it's loaded when I come back. (Example view 1 -> view 2 -> view 1 now it's showed on view 1 and not during first transition...) – Luigi Saggese Nov 25 '13 at 19:08
2

I am doing something similar in one of my apps.

I have a IsLoading property in my ViewModel which I set whether something is loading and not. Then in my ViewController I am subscribing to changes on Loading like this:

ViewModel.WeakSubscribe(() => ViewModel.IsLoading, (sender, args) =>
{
    if (ViewModel.IsLoading)
    {
        ShowLoadingDialog("Loading Resource");
    }
    else
    {
        DismissLoadingDialog();
    }
});

void ShowLoadingDialog(string text)
{
    DismissLoadingDialog();
    BTProgressHUD.Show(text, -1, BTProgressHUD.MaskType.Black);
}

void DismissLoadingDialog()
{
    if (BTProgressHUD.IsVisible)
        BTProgressHUD.Dismiss();
}

I do this in ViewDidLoad(). You could do something similar in your first View, then in your second you could just call DismissLoadingDialog() or simply make sure you call ViewWillDisappear() or ViewDidDisappear(), in the first ViewModel, so it gets dismissed correctly.

Cheesebaron
  • 24,131
  • 15
  • 66
  • 118
2

Loading view controller will not take more then 'Micro Seconds'. Loading data in the view controller will need some time and during that time you need to show that ProgressHUD.

If you are loading data in 'First View Controller' then at start loading data start ProgressHud with BTProgressHUD.Show("test"); and when your data is done loading remove that HUD from the view just before navigating to the 'Second View controller'.

And if, you are loading data in 'Second View Controller', then Do navigation first from 'First View Controller' to 'Second View Controller' and then show HUD just before loading data in Second view controller BTProgressHUD.Show("test"); and remove it after data is loaded.

Mystery
  • 552
  • 6
  • 14