- issue with using performSelector for activityIndicator while calling web service - IOS
- -(void)showActivityIndicator
- {
- CGRect frame = CGRectMake(0.0, 0.0, 125.0, 125.0);
- loading = [[UIActivityIndicatorView alloc] initWithFrame:frame];
- [loading setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
- [loading hidesWhenStopped];
- //loading.center=[self tableView].center;
- [loading startAnimating];
- [loading sizeToFit];
- loading.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
- UIViewAutoresizingFlexibleRightMargin |
- UIViewAutoresizingFlexibleTopMargin |
- UIViewAutoresizingFlexibleBottomMargin);
- // initing the bar button
- //UIBarButtonItem *loadingView = [[UIBarButtonItem alloc] initWithCustomView:loading];
- //loadingView.target = self;
- [loadingView addSubview:loading];
- }
- - (NSDictionary *)fetchJSON:(NSString *)urlString
- {
- NSMutableString *domain = [[NSMutableString alloc] initWithString:@"http://www.blablabla.com/dev/"];
- [domain appendString:urlString];
- //NSLog(@"%@", domain);
- NSURL *url = [NSURL URLWithString:domain];
- NSURLRequest *req = [NSURLRequest requestWithURL:url];
- [self showActivityIndicator];
- [self performSelector:@selector(getData:) withObject:req afterDelay:0.0];
- //[self performSelectorOnMainThread:@selector(getData:) withObject:req waitUntilDone:YES];
- return parsedData;
- }
- -(IBAction)getData:(id)sender
- {
- NSURLResponse* response = nil;
- NSData *data = [NSURLConnection sendSynchronousRequest:sender returningResponse:&response error:nil];
- parsedData = [NSJSONSerialization
- JSONObjectWithData:data
- options:NSJSONReadingMutableLeaves
- error:nil];
- NSLog(@"GET DATA %@", parsedData);
- [loading stopAnimating];
- loading = nil;
- }