gpt4 book ai didi

ios - MBProgressHUD 宽限时间和最小时间无法正常工作。如何实现。

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:41:36 27 4
gpt4 key购买 nike

我正在使用 MBProgressHUD用于在执行本地长方法时显示加载,以提供良好的用户体验。一切正常,但现在我必须这样实现,如果该方法在一秒钟内执行,那么不应出现加载。我浏览了 MBProgressHUD 示例,对于此功能,我发现 setGraceTimesetMinShowTime 显示时间,但它们都无法正常工作。因为当我设置宽限时间时,即使方法执行时间超过 1 秒,加载图标也不会出现。这是我的代码

    if (self.HUD == nil)
{
self.HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:self.HUD];
}
self.HUD.labelText = @"Please wait.....";
// [self.HUD setMinShowTime:2.0f];

[self.HUD setGraceTime:1.0f];
[self.HUD setTaskInProgress:YES];
[self.HUD show:YES];
// [self.HUD hide:YES afterDelay:3];

[[NSRunLoop currentRunLoop] runUntilDate:[NSDate distantPast]];

if (mycondition == nil)
{
[self myTask:[NSURL fileURLWithPath:strPath]];
//[self performSelector:@selector(mytask:) withObject:[NSURL fileURLWithPath:strPath]];
}
else
{
//else
}

self.tempView.hidden = YES;
// self.HUD.taskInProgress = NO;
[self.HUD hide:YES];
self.HUD = nil;

我已经为 this problem's solution 设置了 [[NSRunLoop currentRunLoop] runUntilDate:[NSDate distantPast]];请指导我这段代码有什么问题..?!

最佳答案

您需要在方法执行时从其父 View 中删除 MBProgressHUD 对象。像这样:

// if the method runs inside one second, the indicator will not be shown

- (void)viewDidLoad
{
[super viewDidLoad];
if (HUD == nil)
{
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
}
HUD.labelText = @"Please wait.....";
[HUD setGraceTime:1.0f];
[HUD setTaskInProgress:YES];
[HUD show:YES];
[self performSelector:@selector(runThisMethod) withObject:nil afterDelay:0.9f];
}

- (void)runThisMethod
{
[HUD removeFromSuperview];
}

// if the method runs after one second, the indicator will be shown for some time until the method runs

- (void)viewDidLoad
{
[super viewDidLoad];
if (HUD == nil)
{
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
}
HUD.labelText = @"Please wait.....";
[HUD setGraceTime:1.0f];
[HUD setTaskInProgress:YES];
[HUD show:YES];
[self performSelector:@selector(runThisMethod) withObject:nil afterDelay:1.9f];
}

- (void)runThisMethod
{
[HUD removeFromSuperview];
}

关于ios - MBProgressHUD 宽限时间和最小时间无法正常工作。如何实现。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18008708/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com