I need to add an activityIndicator to a UIView.I have a button,when that button is clicked then it has to start animating. Actually when the button is clicked some data is received from rest service and parsing is done and then it is filled in UITableView.But the activity indicator is not getting animating..
- (void)viewDidLoad
{
[super viewDidLoad];
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc]
initWithFrame:CGRectMake(0.0f, 0.0f, 20.0f, 20.0f)];
[activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];
[self.view addSubview:activityIndicator];
}
-(IBAction)switchtoGetProviders
{
[activityIndicator startAnimating];
NSURL *urlString= [NSString stringWithFormat:@"http://230.32.232.32/services/service.svc/Xml"];
NSMutableURLRequest *request=[[[NSMutableURLRequest alloc] init]autorelease];
..............//calling data from service url
}
After reciving the whole data it is assigned to UITableView.
How can I get it working ?
Probably this is due to the fact that you are making the webservice call and updating the UI at the same time on MAIN Thread. You must use GCD or detach another thread for making the webservice call.
Use this to detach a new thread
In your code