gpt4 book ai didi

iphone - 如何在 iOS 上的按钮操作上显示忙碌指示器?

转载 作者:行者123 更新时间:2023-12-01 17:59:56 24 4
gpt4 key购买 nike

我想在按钮操作上启动繁忙指示器,我在 IB 操作中使用以下代码:

 busyIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
busyIndicator.center = self.view.center;
[busyIndicator setColor:[UIColor redColor]];
[self.btnInjuryPrevention addSubview:busyIndicator];
[self.view addSubview:busyIndicator]; // spinner is not visible until started

[busyIndicator startAnimating];
if(![AppStatus isAppOnline]) {
noInternetViewController = [[NoInternetViewController alloc] initWithNibName:@"NoInternetViewController" bundle:[NSBundle mainBundle]];
noInternetViewController.view.tag = CHILD_CONTROLLER_TAG;
[self.navigationController pushViewController:noInternetViewController animated:YES];
NSLog(@"Yoy are offline..>!!");
}
else
{
mInjuryPreventionViewController=[[InjuryPreventionViewController alloc] initWithNibName:@"InjuryPreventionViewController" bundle:nil withHeader:@" Injury Prevention" withId:INJURY_PREVENTION_ID];
mInjuryPreventionViewController.view.tag = CHILD_CONTROLLER_TAG;
[self.navigationController pushViewController:mInjuryPreventionViewController animated:YES];
//[mInjuryPreventionViewController release];
}
// [self removeLoadingView];
[busyIndicator stopAnimating];

我使用上面的代码,但是繁忙的指示器不会启动,所以你能告诉我这可能吗?

最佳答案

如果您在单个 block 中启动和停止动画,您将看不到任何内容。你可以想到startAnimating方法表示“当控制返回操作系统时开始动画”。

目前尚不清楚为什么你需要一个微调器。创建 View Controller 需要很长时间吗?不过,如果您将 View Controller 的内容移动到新方法中,您可以执行以下操作:

...
// create busy indicator
[busyIndicator startAnimating];
[self performSelector:@selector(createViewController) withObject:nil afterDelay:0];

...

// at the end of the createViewController method...
[busyIndicator stopAnimating];

关于iphone - 如何在 iOS 上的按钮操作上显示忙碌指示器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11647540/

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