I have a Login page in that when i press "login" button i have to call a webservice and load new view according to the response it is taking 3 to 4 seconds i want to show activity indicator for loading view
how to show that
i'm using asynchronous NSURLConnection with NSURLConnection delegates
NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
[conn start];
in didFinishLoading
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSError *e = nil;
res = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&e];
//[indicator performSelectorOnMainThread:@selector(stopAnimating) withObject:nil waitUntilDone:YES];
NSLog(@"data is %@",res);
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"create.json"];
NSLog(@"file path is %@ ",path);
NSFileManager *fileManager=[NSFileManager defaultManager];
if(![fileManager fileExistsAtPath:path])
{
NSString *bundle = [[[NSBundle mainBundle]resourcePath]stringByAppendingString:@"create.json"];
[fileManager copyItemAtPath:bundle toPath:path error:&error];
}
[res writeToFile:path atomically:YES];
how to show in this view
i stucked here
In your
@interface
, add:When you start your connection, start your spinner:
And when your connection completes, remove it:
Make sure you remove it the same way in the
connectionDidFailWithError:
callback as well. If you want something prettier, check out the github link @evnaz posted and use that instead ofUIActivityIndicatorView
with this same flow