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.
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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With