2017-04-21 1 views
0

J'utilise VBPieChart, en langage Objective C. Je montre le tableau sur valueChange d'un contrôle segmenté, comme:VBPieChart - removeFromSuperView ne fonctionne pas (masquer le graphique)

- (IBAction)segmentControlAction:(UISegmentedControl *)sender 
    { 
    switch ([sender selectedSegmentIndex]) 
    { 
     case 0: 

      [self showPieChart:NO]; 
      _tableViewForCount.hidden = NO; 
      [_tableViewForCount reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationRight]; 

      break; 
     case 1: 

      _tableViewForCount.hidden = YES; 

      [self showPieChart:YES]; 

      break; 
     default: 
      NSLog(@"None"); 
      break; 
    } 
} 

et la méthode showPieChart va comme:

- (void) showPieChart:(Boolean)visible 
{ 
    VBPieChart *chart = [[VBPieChart alloc] initWithFrame:CGRectMake(0, 0, 250, 250)]; 
    chart.center = self.view.center; 

    // Setup some options: 
    [chart setHoleRadiusPrecent:0.3]; /* hole inside of chart */ 

    // Prepare your data 
    NSMutableArray *chartValues = [[NSMutableArray alloc]initWithObjects:        @{@"name":@"Apples", @"value":@50, @"color":[UIColor redColor]}, 
          @{@"name":@"Pears", @"value":@20, @"color":[UIColor blueColor]}, 
          @{@"name":@"Oranges", @"value":@40, @"color":[UIColor orangeColor]}, 
          @{@"name":@"Bananas", @"value":@70, @"color":[UIColor purpleColor]}, nil 
          ]; 


    if (visible) 
    { 
     chart.center = self.view.center; 
     // Present pie chart with animation 
     [chart setChartValues:chartValues animation:YES duration:0.4 options:VBPieChartAnimationFan]; 
     [self.view addSubview:chart]; 
    } 
    else 
    { 
     // remove chart 
     [chart removeFromSuperView]; 
    } 
} 

Depuis VBPieChart est juste une sous-classe personnalisée de UIView, cela devrait fonctionner. Mais je ne reçois aucun succès. J'ai également essayé [chart setHidden:YES]; ainsi que , mais toujours pas de chance.

Toute aide serait appréciée. Je veux juste cacher/enlever le tableau quand l'utilisateur est revenu à l'index de segment 0.

Merci.

Répondre

1

VBPieChart * Tableau créer cet objet sur le fichier .h puis

- (void) showPieChart:(Boolean)visible 
{ 
    if(chart == nil) 
    { 
     chart = [[VBPieChart alloc] initWithFrame:CGRectMake(0, 0, 250, 250)]; 
     [self.view addSubview:chart]; 
    } 
    chart.center = self.view.center; 

    // Setup some options: 
    [chart setHoleRadiusPrecent:0.3]; /* hole inside of chart */ 

    // Prepare your data 
    NSMutableArray *chartValues = [[NSMutableArray alloc]initWithObjects:        @{@"name":@"Apples", @"value":@50, @"color":[UIColor redColor]}, 
          @{@"name":@"Pears", @"value":@20, @"color":[UIColor blueColor]}, 
          @{@"name":@"Oranges", @"value":@40, @"color":[UIColor orangeColor]}, 
          @{@"name":@"Bananas", @"value":@70, @"color":[UIColor purpleColor]}, nil 
          ]; 


    if (visible) 
    { 
     chart.center = self.view.center; 
     // Present pie chart with animation 
     [chart setChartValues:chartValues animation:YES duration:0.4 options:VBPieChartAnimationFan]; 
     chart.alpa = 1.0 
    } 
    else 
    { 
     // remove chart 
     chart.alpa = 0.0 
    } 
} 
+0

Merci. fonctionne comme un charme. –

+0

@RajD Le plus apprécié Codage heureux! –

0

Vous devez créer la variable comme ci-dessous.

static VBPieChart *chart = nil 
if(!chart) 
    chart = [[VBPieChart alloc] initWithFrame:CGRectMake(0, 0, 250, 250)]; 
    } 
    if (visible) 
    { 
     chart.hidden = NO; 
    } 
    else 
    { 
     // hide chart 
     chart.hidden = YES; 
    }