Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 3rd, 2012  |  syntax: None  |  size: 1.89 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. issue with using performSelector for activityIndicator while calling web service - IOS
  2. -(void)showActivityIndicator
  3. {
  4.     CGRect frame = CGRectMake(0.0, 0.0, 125.0, 125.0);
  5.     loading = [[UIActivityIndicatorView alloc] initWithFrame:frame];
  6.     [loading setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
  7.     [loading hidesWhenStopped];
  8.     //loading.center=[self tableView].center;
  9.     [loading startAnimating];
  10.     [loading sizeToFit];
  11.     loading.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
  12.                                 UIViewAutoresizingFlexibleRightMargin |
  13.                                 UIViewAutoresizingFlexibleTopMargin |
  14.                                 UIViewAutoresizingFlexibleBottomMargin);
  15.  
  16.     // initing the bar button
  17.     //UIBarButtonItem *loadingView = [[UIBarButtonItem alloc] initWithCustomView:loading];
  18.     //loadingView.target = self;
  19.  
  20.     [loadingView addSubview:loading];
  21. }
  22.  
  23.  
  24. - (NSDictionary *)fetchJSON:(NSString *)urlString
  25. {
  26.     NSMutableString *domain = [[NSMutableString alloc] initWithString:@"http://www.blablabla.com/dev/"];
  27.     [domain appendString:urlString];
  28.     //NSLog(@"%@", domain);
  29.     NSURL *url = [NSURL URLWithString:domain];
  30.     NSURLRequest *req = [NSURLRequest requestWithURL:url];
  31.  
  32.     [self showActivityIndicator];
  33.     [self performSelector:@selector(getData:) withObject:req afterDelay:0.0];
  34.     //[self performSelectorOnMainThread:@selector(getData:) withObject:req waitUntilDone:YES];
  35.  
  36.     return parsedData;
  37. }
  38.  
  39. -(IBAction)getData:(id)sender
  40. {  
  41.     NSURLResponse* response = nil;
  42.     NSData *data = [NSURLConnection sendSynchronousRequest:sender returningResponse:&response error:nil];
  43.     parsedData = [NSJSONSerialization
  44.                   JSONObjectWithData:data
  45.                   options:NSJSONReadingMutableLeaves
  46.                   error:nil];
  47.     NSLog(@"GET DATA %@", parsedData);
  48.     [loading stopAnimating];
  49.     loading = nil;
  50. }