tags:

views:

148

answers:

1

I am implementing an activity indicator in my application. In my application on button click a webservice is called and it takes some time. To show the user that process is going on I implemented an activity indicator:

CGRect frame = CGRectMake(140, 300, 40, 37); 
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:frame];
activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray; 
[self.view  addSubview:activityIndicator];

This Snippet is written in viewDidLoad() method, and I have an action called,

-(IBAction)agree:(id)sender
{ 
 //here webservice is called
}

I have to start that activity by [activityIndicator startAnimating];

But I am unable to start that activityIndicator, please suggest a proper solution for that.

+1  A: 

Put this code into your web view.

 -(void) viewDidLoad
{ 
   activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

  activityIndicator.frame = CGRectMake(0.0, 0.0, 20.0, 20.0);

   activityIndicator.center=self.view.center;

  [activityIndicator startAnimating];

  [self.view addSubview:activityIndicator];
 }

  - (void)webViewDidStartLoad:(UIWebView *)webView
   {

       [activityIndicator startAnimating];

  }

 - (void)webViewDidFinishLoad:(UIWebView *)webView
 {

   [activityIndicator stopAnimating];

  }

Refer this link link text. This explains to display the activity indicator for parsing action of the rss feed

Best of Luck.

Pugal Devan
Sorry but i don't want to start it in viewDidLoad , i want to start it on agree button click before webservice start calling, but it is nt working.
Prash.......
@Prash..... You dont need to put in DidLoad method. You just put where do you want the activity indicator. Have You used XML parser in your apps. Tried that the above link, it may help you.
Pugal Devan