gpt4 book ai didi

objective-c - 按下按钮上传下一个 View 或 webview 时如何显示事件指示器?

转载 作者:可可西里 更新时间:2023-11-01 06:23:50 25 4
gpt4 key购买 nike

My first view is looks like  this 当我单击标题为“单击此处放大”的按钮时,我想在第一个 View 上显示事件指示器并在加载此 View 时删除。 second view in which image is upload from URL in image view.

但是我回去然后它显示了此 View 中显示的事件指示器。 first view with activity indicator

在第一个 vie .m 文件中,我使用此代码进行操作。

-(IBAction)btnSelected:(id)sender{
UIButton *button = (UIButton *)sender;
int whichButton = button.tag;
NSLog(@"Current TAG: %i", whichButton);
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[spinner setCenter:CGPointMake(160,124)];
[self.view addSubview:spinner];
[spinner startAnimating];

if(whichButton==1)
{
[spinner stopAnimating];

first=[[FirstImage alloc]init];
[self.navigationController pushViewController:first animated:YES];
[spinner hidesWhenStopped ];

}}

在上面的代码中,我有一个按钮操作,我在其中调用了下一个 View 。现在我想在查看上传时显示/显示事件指示器。在下一个 View 中,我有一个 ImageView ,其中我上传的图像我声明了一个事件指示器,该指示器也不起作用。怎么做到的?

最佳答案

Toro 的建议提供了很好的解释和解决方案,但我只是想提供另一种实现方式,因为我就是这样做的。

正如托罗所说,

- (void) someFunction
{
[activityIndicator startAnimation];

// do computations ....

[activityIndicator stopAnimation];
}

上面的代码将不起作用,因为当您在当前运行的函数中包含 activityIndi​​cator 时,您没有给 UI 更新时间。所以我和许多其他人所做的就是将它分解成一个单独的线程,如下所示:

- (void) yourMainFunction {
activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

[NSThread detachNewThreadSelector:@selector(threadStartAnimating) toTarget:self withObject:nil];

//Your computations

[activityIndicator stopAnimating];

}

- (void) threadStartAnimating {
[activityIndicator startAnimating];
}

祝你好运!-卡罗利

关于objective-c - 按下按钮上传下一个 View 或 webview 时如何显示事件指示器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6829279/

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