what’s wrong with my code?
i want spinner indicator start when view1.nib start to load.
so i put [spinner startAnimating]; in – (void)viewDidLoad .
but it will get that url then start spinner indicator…
- (void)viewDidLoad {
[spinner startAnimating];
NSURL *originalUrl=[NSURL URLWithString:@"http://example.com/"];
NSData *data=nil;
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:originalUrl cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10];
NSURLResponse *response;
NSError *error;
data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSURL *LastURL=[response URL];
NSLog(@"%@",LastURL);
[backr,backrm,downloadr setEnabled:FALSE];
backr.hidden=YES;
backrm.hidden=YES;
downloadr.hidden=YES;
[self nextr:0];
[super viewDidLoad];
}
Your problem is that block your main thread using the sendSynchronousRequest.
While the data is downloading your thread is blocking and so your animation too, and after the request has been done the animation continue.
I should you to use the connectionWithRequest:delegate: or the initWithRequest:delegate: methods and set the delegate to self.
You can find more information here: Using NSURLConnection
EDIT:
Example:
In your interface define it:
then in your controller into the viewDidLoad:
to finish, again in you controller, implement these methods: