开发者

Activity Indicator

开发者 https://www.devze.com 2023-03-10 21:05 出处:网络
I want to use activity indicator in my app. I am using to JSON Parsing in my app. first when i click the sync button when ever the data download activity indicator is display & when download开发者

I want to use activity indicator in my app.

I am using to JSON Parsing in my app. first when i click the sync button when ever the data download activity indicator is display & when download开发者_开发技巧ing complete it stop.

Same isuue is here, When app start data is downloadin at that time i also put activity indicator in app.

I am using below methods for connection...

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{

}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{

}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{

}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{

}


 UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
 [indicator setCenter:CGPointMake(YourXPoint, YourYPoint)];
 [self.view addSubview:indicator];
 [indicator startAnimating];   

and when you want to stop indicator use this

  [indicator stopAnimating]; 


You can use the given below line to start activity indicator visible to user , this line to be used when you start parsing JSON

[UIApplication sharedApplication].networkActivityIndicatorVisible=YES;

The above line will show the activity indicator on status bar

To stop put the line in didfinishloading and didfailwitherror methods

[UIApplication sharedApplication].networkActivityIndicatorVisible=NO;


You need declare an instance variable of type UIActivityIndicatorView in your class. thats the only way to go.

You can initialize it in viewDidLoad method.

When you want to make an asycn. call use startAnimating on that activityIndicator variable and in

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{

}

You should use stopAnimation on your activityIndicator variable.

0

精彩评论

暂无评论...
验证码 换一张
取 消