1

I don't know how to explain but... If you understand me when I say a "loading circle" perfect, I just want to do this

    // 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

Probabbly I have to add a thread or something but I don't know how to do what I want exactly I hope you can help me, again. Thanks.

EDIT:

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;
    });
});

Two things

 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"

Thanks =)

Alejandro L.
  • 1,066
  • 5
  • 17
  • 38

6 Answers6

4

It can be done using MBProgressHUD

Also check this code:

//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
            });

});

EDIT:

Never call methods like:

activityIndicator.startAnimating;
activityIndicator.stopAnimating;

These are used for calling setters and getters.

Change it to:

[activityIndicator startAnimating];
[activityIndicator stopAnimating];
Midhun MP
  • 103,496
  • 31
  • 153
  • 200
3

You can use a UIActivityIndicatorView.

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];

Also, like shown by Midhun MP, you may have to use asynchronism to, for example, load data while your indicator is showing.

Rob
  • 15,732
  • 22
  • 69
  • 107
1

May be you can try Activity Indicator.

iCodes
  • 1,382
  • 3
  • 21
  • 47
  • to start animating, use [activityIndicator startAnimating]; and to stop animating, use [activityIndicator stopAnimating]; – lakshmen Jan 23 '13 at 10:40
1

You can try using svprogresshud

lakshmen
  • 28,346
  • 66
  • 178
  • 276
1

You can alter the style of activityindicator,

UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActionSheetStyleDefault];
    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActionSheetStyleBlackOpaque];
    UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActionSheetStyleBlackTranslucent];

use any of these styles.

And This link can help to solve your second issue xCode "Property access results unused - getters should not be used for side effects"

SOLUTION: instead of using activityIndicator.startAnimating; and activityIndicator.stopAnimating use [activityIndicator startAnimating]; and [activityIndicator stopAnimating];

Community
  • 1
  • 1
DD_
  • 7,230
  • 11
  • 38
  • 59
  • A question cannot have multiple answers! One that fills all your requirements can be accepted as the real answer! Your choice – DD_ Jan 23 '13 at 11:14
  • All answers helped and I feel very helped in this page I vote up those who helped me and I select the "main" answer the most completed answer for my question. I really appreciate your help. – Alejandro L. Jan 23 '13 at 11:30
0

For changing the size of the activity indicator:

activityIndicator.frame = CGRectMake(0.0, 0.0, 80.0, 80.0);
activityIndicator.transform = CGAffineTransformMakeScale(1.75, 1.75);

By the way, if you are populating a tableview, you may consider enabling the user interaction at the same time you launch the activity indicator:

[activityIndicator startAnimating];
tableView.userInteractionEnabled = NO;

and restoring it after:

[self.tableView reloadData];
[activityIndicator stopAnimating];
tableView.userInteractionEnabled = YES;
MLBDG
  • 1,357
  • 17
  • 23