VBPieChart - removeFromSuperView 不工作(隐藏图表)
VBPieChart - removeFromSuperView not working (hide chart)
我正在使用 VBPieChart,语言是 Objective C。我在分段控件的 valueChange
上显示图表,例如:
- (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
方法如下:
- (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];
}
}
因为 VBPieChart
只是 UIView 的自定义子类,所以这应该可行。但我没有取得任何成功。
我也试过 [chart setHidden:YES];
和 [chart setAlpha:0.0];
,但还是不行。
如有任何帮助,我们将不胜感激。当用户切换回段索引 0 时,我只想 hide/remove 图表。
谢谢。
VBPieChart *chart 在 .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
}
}
您需要创建如下变量。
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;
}
我正在使用 VBPieChart,语言是 Objective C。我在分段控件的 valueChange
上显示图表,例如:
- (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
方法如下:
- (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];
}
}
因为 VBPieChart
只是 UIView 的自定义子类,所以这应该可行。但我没有取得任何成功。
我也试过 [chart setHidden:YES];
和 [chart setAlpha:0.0];
,但还是不行。
如有任何帮助,我们将不胜感激。当用户切换回段索引 0 时,我只想 hide/remove 图表。
谢谢。
VBPieChart *chart 在 .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
}
}
您需要创建如下变量。
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;
}