gpt4 book ai didi

ios - 如何在我的iOS应用程序中添加UIActivityIndi​​cator View?

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

我不知道该怎么解释,但是...如果当我说“加载圆”完美时您理解我,我只想这样做

    // Start loading in the middle of the screen frozing all interaction
for (int c = 0; c < ([barcos count] - 1); c++)
{
NSArray *datos = [[barcos objectAtIndex:c] componentsSeparatedByString:@";"];
NSString *nombreImagen = [datos objectAtIndex:2];
NSURL *accesoFtp = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",urlFtp,nombreImagen]];
NSData *imagen = [NSData dataWithContentsOfURL:accesoFtp];
[imagen writeToFile:[[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"Barcos/%@",nombreImagen]]] atomically:NO];
}
// Stop frozing all interaction and remove the loading circle

可能我必须添加线程或其他内容,但是我不知道该怎么做,我希望您能再次帮助我。谢谢。

编辑:
UIActivityIndicatorView *activityIndicator;
activityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
activityIndicator.frame = CGRectMake(0.0, 0.0, 40.0, 40.0);
activityIndicator.center = self.view.center;
[self.view addSubview: activityIndicator];

activityIndicator.startAnimating;

dispatch_queue_t queue = dispatch_get_global_queue(0,0);

dispatch_async(queue, ^{

for (int c = 0; c < ([barcos count] - 1); c++)
{
NSArray *datos = [[barcos objectAtIndex:c] componentsSeparatedByString:@";"];
NSString *nombreImagen = [datos objectAtIndex:2];
NSURL *accesoFtp = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",urlFtp,nombreImagen]];
NSData *imagen = [NSData dataWithContentsOfURL:accesoFtp];
[imagen writeToFile:[[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"Barcos/%@",nombreImagen]]] atomically:NO];
}

dispatch_sync(dispatch_get_main_queue(), ^{
activityIndicator.stopAnimating;
});
});

两件事情
 1.- The activity indicator is too small but works, if I can to it bigger or same size but make darker the background would be better (Thanks!)
2.- I have a warning with startAnimating and stopAnimating "Property access result unused - getters should not be used for side effects"

谢谢=)

最佳答案

可以使用MBProgressHUD完成

还要检查以下代码:

//Show your activity indicator here

dispatch_queue_t queue = dispatch_get_global_queue(0,0);

dispatch_async(queue, ^{
for (int c = 0; c < ([barcos count] - 1); c++)
{
NSArray *datos = [[barcos objectAtIndex:c] componentsSeparatedByString:@";"];
NSString *nombreImagen = [datos objectAtIndex:2];
NSURL *accesoFtp = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",urlFtp,nombreImagen]];
NSData *imagen = [NSData dataWithContentsOfURL:accesoFtp];
[imagen writeToFile:[[NSString alloc] initWithString: [docsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"Barcos/%@",nombreImagen]]] atomically:NO];
}
dispatch_sync(dispatch_get_main_queue(), ^{
//hide that activity indicator here
});

});

编辑:

永远不要调用以下方法:
activityIndicator.startAnimating;
activityIndicator.stopAnimating;

这些用于调用setter和getter。

更改为:
[activityIndicator startAnimating];
[activityIndicator stopAnimating];

关于ios - 如何在我的iOS应用程序中添加UIActivityIndi​​cator View?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14477253/

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