2017-04-21 1 views
0

VBPieChart을 Objective C 언어로 사용하고 있습니다. 내가 좋아하는, 세그먼트 컨트롤의 valueChange에 차트를 보여주는 해요 :VBPieChart - removeFromSuperView가 작동하지 않습니다 (차트 숨기기)

- (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; 
    } 
} 

showPieChart 방법은 같이 간다 : VBPieChart 이후

- (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]; 
    } 
} 

는 UIView의 단지 사용자 정의 서브 클래스이며,이 작업을해야합니다. 그러나 나는 어떤 성공도 얻지 못하고있다.

나는 또한 [chart setAlpha:0.0];과 마찬가지로 [chart setHidden:YES];을 시도했지만 아직 행운은 없습니다.

어떤 도움을 주시면 감사하겠습니다. 사용자가 세그먼트 인덱스 0으로 전환했을 때 차트를 숨기거나 제거하고 싶습니다.

감사합니다.

답변

1

VBPieChart *이 차트는 .H 파일에이 객체를 생성 한 후

- (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

고맙습니다. 매력처럼 작동합니다. –

+0

@RajD 해피 코딩을 가장 환영합니다! –

0

당신은 아래의 변수를 작성해야합니다.

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; 
    } 
관련 문제