IRD
IRD

Reputation: 1157

Programmatically created activity indicator not removing

I want to add an ActivityIndicator onto UIButton So I did like this

-(IBAction)SetNationality:(id)sender
{

actInd=[[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
[btnpost addSubview:actInd];
[actInd startAnimating];

NSMutableDictionary *dictionaly=[[NSMutableDictionary alloc] init];
[dictionaly setValue:[NSNumber numberWithInt:0] forKey:@"NationalityCode"];
[dictionaly setValue:@"nationalitytest test" forKey:@"NationalityName"];
[dictionaly setValue:[NSNumber numberWithInt:0] forKey:@"Deleted"];
[dictionaly setValue:[NSNumber numberWithInt:1] forKey:@"Status"];

NSMutableDictionary *dictNationality=[[NSMutableDictionary alloc] init];
[dictNationality setObject:dictionaly forKey:@"Nationality"];


 [wb prepareURL:@"ProfileConfig/Nationalities" :@"" :YES :NO :dictNationality:^(NSString *status)
{

    [self DataReceived];



    }];
}

Then I remove that activity indicator inside this method

-(void)DataReceived
 {

  [actInd removeFromSuperview];
  NSLog(@"data array %@",dm.arrayData);
  }

But my problem is activityindicator not removing from the super view. Its keep rotating. How can I solve this problem. Thanks

Upvotes: 0

Views: 481

Answers (3)

soumya
soumya

Reputation: 3811

Hope this helps you:

- (void) hideActivityIndicator {

    actInd.hidden = YES;
    [UIView animateWithDuration:0.3 animations:^{
    actInd.alpha = 0.0;
   }  completion:^(BOOL finished) {
     [actInd stopAnimating];

   }];

}

Upvotes: 0

Dharmesh Dhorajiya
Dharmesh Dhorajiya

Reputation: 3984

try this code :

-(void)DataReceived
 {

    dispatch_async(dispatch_get_main_queue(), ^{
       [actInd stopAnimating];
       [actInd removeFromSuperview];
        // do your UI updates here...
    });

  NSLog(@"data array %@",dm.arrayData);
  }

Upvotes: 2

Maddy
Maddy

Reputation: 389

No need to remove activity indicator from the parent view. Just stop the activity indicator animating.

-(void)DataReceived
{
   dispatch_async(dispatch_get_main_queue(), ^{
       [actInd stopAnimating];
   });
}

Upvotes: 2

Related Questions