简体   繁体   English

ProgressHUD和TouchUpInside

[英]ProgressHUD and TouchUpInside

I have my ViewController like 我有我的ViewController

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

and i load my next ViewController on button event TouchUpInside like that: 我在按钮事件TouchUpInside上加载我的下一个ViewController,如下所示:

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

that event it's defined in ViewDidLoad. 它在ViewDidLoad中定义的那个事件。 My "test" message it's showed on next ViewController and not during loading of this one. 我在下一个ViewController上显示的“测试”消息,而不是在加载这个消息时。 How could i show that message during loading and not when next ViewController is loaded? 如何在加载期间显示该消息,而不是在下一个ViewController加载时? I have tried to use also MBProgressHUD 我也尝试过使用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. 您似乎正在尝试在View层中使用ProgressHUD。 In MVVM-way you should create a "Loading" property in your ViewModel and bind it to progressbar in View. 在MVVM方式中,您应该在ViewModel中创建一个“加载”属性,并将其绑定到View中的进度条。

Here is a good Stuart's video how to do that: http://youtu.be/6fNXGErr9to 这是一个很好的斯图亚特的视频如何做到这一点:http: //youtu.be/6fNXGErr9to

And here is sample code: https://github.com/MvvmCross/NPlus1DaysOfMvvmCross/tree/master/N-34-Progress 以下是示例代码: 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. 我在我的ViewModel有一个IsLoading属性,我设置是否正在加载,而不是。 Then in my ViewController I am subscribing to changes on Loading like this: 然后在我的ViewController我订阅了像这样的Loading更改:

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() . 我在ViewDidLoad()执行此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. 您可以在第一个视图中执行类似的操作,然后在第二个视图中,您可以调用DismissLoadingDialog()或者只是确保在第一个ViewModel中调用ViewWillDisappear()ViewDidDisappear() ,这样它就会被正确解除。

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. 在视图控制器中加载数据需要一些时间,在此期间您需要显示ProgressHUD。

If you are loading data in 'First View Controller' then at start loading data start ProgressHud with BTProgressHUD.Show("test"); 如果要在“First View Controller”中加载数据,则在开始加载数据时,使用BTProgressHUD.Show("test");启动ProgressHud BTProgressHUD.Show("test"); and when your data is done loading remove that HUD from the view just before navigating to the 'Second View controller'. 当您的数据完成后,在导航到“第二视图控制器”之前,从视图中删除该HUD。

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"); 如果您要在“第二视图控制器”中加载数据,则首先从“第一视图控制器”导航到“第二视图控制器”,然后在第二视图控制器BTProgressHUD.Show("test");加载数据之前显示HUD BTProgressHUD.Show("test"); and remove it after data is loaded. 并在加载数据后将其删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM