Implement UIActivityIndicatorView when loading NSData dataWithContentsOfURL

I download mp3 using NSData dataWithContentsOfURL: url. This takes some time, and while the file is loading, the application freezes. I want to work well, and the ideal would like to show the boot process, but cannot find methods for this.

This is in the UIViewController, and I made my first attempt by placing it in the UIActivityIndicatorView and starting to rotate it before starting to load, and then stop its rotation, but nothing appears.

So my question is really, please, can someone tell me what is the best way to handle this? Many thanks

+3
source share
2

, , - , .

NSUrlConnection / .

, NSData dataWithContentsOfURL:url, .

+4

, , .

, performSelector:withObject:afterDelay: 0, ( , ), .

:

- (void)loadPart1 {
  activityIndicator = [[[UIActivityIndicatorView alloc]
                        initWithActivityIndicatorStyle:UIA...StyleGray]
                       autorelease];
  activityIndicator.frame = myFrame;
  [self.view addSubview:activityIndicator];
  [activityIndicator startAnimating];
  [self performSelector:@selector(loadPart2) withObject:nil afterDelay:0];
}

- (void)loadPart2 {
  [NSURLConnection sendSynchronousRequest:request returningResponse:&response
                                    error:&error];
  [activityIndicator stopAnimating];
}

: http://bynomial.com/blog/?p=15 ( 1 2).

+3

Source: https://habr.com/ru/post/1744793/


All Articles