tags:

views:

178

answers:

1

hi, i use NSobject class inwhich i have NSURLConnection,but how can i show UIActivityIndicatorView when connection established and finished.....?i tried in appdelegate.m file inwhich i have mentioned in appdidfnish method

    Search = [[UIActivityIndicatorView alloc]  
    initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
     [Search setCenter:CGPointMake(160, 240)]; 
     [window addSubview: Search];

and also i have individual method like

      -(void)anim
{
   [search startAnimating];
}

but if i call this method through appdelegate object in NSobject.m page, it will not work.. what i have to do? any help? please?

A: 

I'm not sure, but where are you setting the frame of your activityIndicatorView? I've just tried this piece of code and it works perfect.

  activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
 [activityIndicator setCenter:CGPointMake(160, 240)];
 [activityIndicator startAnimating];
[window addSubview:activityIndicator];
UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(100, 300, 120, 50)];
[button setTitle:@"press me" forState:UIControlStateNormal];
[button addTarget:self action:@selector(onBtnClk) forControlEvents:UIControlEventTouchUpInside];
[window addSubview:button];
[window makeKeyAndVisible];

and this is onBtnClk method

- (void) onBtnClk{
if([activityIndicator isAnimating]){
 [activityIndicator stopAnimating];
}else{
 [activityIndicator startAnimating];
}

}

Morion
normally if we declare like following it works in view controller...Search = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; [Search setCenter:CGPointMake(160, 240)]; [window addSubview: Search];-(void)anim{ [search startAnimating];}
Mikhail Naimy
but i cannot stop in other methods like [activityIndicator startAnimating];because it is declared as local variable
Mikhail Naimy