我正在使用名为TWRCharts的iOS图表软件,我正在尝试在同一个视图控制器中添加多个图表。我使用Interface Builder添加了UIViews,并使用我的.h文件中的outlet连接它们。当我尝试显示一个图表时,我的主图表显示正常。但是当我尝试添加更多图表时,它们不会出现。我试图颠倒图表绘制的顺序,在这种情况下,会出现一个较小的图表,但没有别的。当我尝试将多个子视图添加到各自的视图时,不会显示任何内容。这是我的.h和.m文件。
·H
#import <UIKit/UIKit.h>
#import "TWRChart.h"
@interface OverviewViewController : UIViewController
- (IBAction)didTapButton:(id)sender;
@property (strong, nonatomic) IBOutlet UIView *mainCircularChartUIView;
@property (strong, nonatomic) TWRChartView *mainCircularChart;
@property (strong, nonatomic) IBOutlet UIView *tapTestCircularChartUIView;
@property (strong, nonatomic) TWRChartView *tapTestCircularChart;
@property (strong, nonatomic) IBOutlet UIView *cogTestCircularChartUIView;
@property (strong, nonatomic) TWRChartView *cogTestCircularChart;
@property (strong, nonatomic) IBOutlet UIView *voiceTestCircularChartUIView;
@property (strong, nonatomic) TWRChartView *voiceTestCircularChart;
@property (strong, nonatomic) IBOutlet UIView *mentalHealthTestControllerUIView;
@property (strong, nonatomic) TWRChartView *mentalHealthTestController;
@end
.m(目前正在评论添加多个子视图)
- (void)viewDidLoad {
[super viewDidLoad];
/////////// Main Circular Chart View ////////////////////////
self.mainCircularChart = [[TWRChartView alloc] initWithFrame:CGRectMake(0, 60, 300, 300)];
self.mainCircularChart.backgroundColor = [UIColor clearColor];
self.mainCircularChart.userInteractionEnabled = YES;
// Add the chart view to the controller's view
[self.mainCircularChartUIView addSubview:self.mainCircularChart];
/////////// Sub Circular Chart Views ////////////////////////
self.tapTestCircularChart = [[TWRChartView alloc] initWithFrame:CGRectMake(0, 0, 75, 75)];
self.tapTestCircularChart.backgroundColor = [UIColor clearColor];
self.tapTestCircularChart.userInteractionEnabled = YES;
self.cogTestCircularChart = [[TWRChartView alloc] initWithFrame:CGRectMake(0, 0, 75, 75)];
self.cogTestCircularChart.backgroundColor = [UIColor clearColor];
self.cogTestCircularChart.userInteractionEnabled = YES;
// Add the chart view to the controller's view
// [self.tapTestCircularChartUIView addSubview:self.tapTestCircularChart];
// [self.cogTestCircularChartUIView addSubview:self.cogTestCircularChart];
[self loadMainCircularChart];
[self loadSubCircularCharts];
}
- (void)loadSubCircularCharts {
// Values
NSArray *values = @[@20, @30, @15, @5];
// Colors
UIColor *color1 = [UIColor colorWithHue:0.5 saturation:0.6 brightness:0.6 alpha:1.0];
UIColor *color2 = [UIColor colorWithHue:0.6 saturation:0.6 brightness:0.6 alpha:1.0];
UIColor *color3 = [UIColor colorWithHue:0.7 saturation:0.6 brightness:0.6 alpha:1.0];
UIColor *color4 = [UIColor colorWithHue:0.8 saturation:0.6 brightness:0.6 alpha:1.0];
NSArray *colors = @[color1, color2, color3, color4];
// Tap Test Chart ///////////////////////////////////////////
TWRCircularChart *tapTestChart = [[TWRCircularChart alloc] initWithValues:values colors:colors type:TWRCircularChartTypeDoughnut animated:YES];
[self.tapTestCircularChart loadCircularChart:tapTestChart];
// Cog Test Chart ///////////////////////////////////////////
TWRCircularChart *cogTestChart = [[TWRCircularChart alloc] initWithValues:values colors:colors type:TWRCircularChartTypeDoughnut animated:YES];
//
[self.tapTestCircularChart loadCircularChart:cogTestChart];
}
- (void)loadMainCircularChart {
// Values
NSArray *values = @[@20, @30, @15, @5];
// Colors
UIColor *color1 = [UIColor colorWithHue:0.5 saturation:0.6 brightness:0.6 alpha:1.0];
UIColor *color2 = [UIColor colorWithHue:0.6 saturation:0.6 brightness:0.6 alpha:1.0];
UIColor *color3 = [UIColor colorWithHue:0.7 saturation:0.6 brightness:0.6 alpha:1.0];
UIColor *color4 = [UIColor colorWithHue:0.8 saturation:0.6 brightness:0.6 alpha:1.0];
NSArray *colors = @[color1, color2, color3, color4];
// Doughnut Chart
TWRCircularChart *pieChart = [[TWRCircularChart alloc] initWithValues:values colors:colors type:TWRCircularChartTypeDoughnut animated:YES];
[self.mainCircularChart loadCircularChart:pieChart];
}
答案 0 :(得分:1)
您可以通过两种方式实施
如果您在使用滚动视图时遇到问题
答案 1 :(得分:0)
您是否添加了UIScrollView作为VC的主要子视图?如果没有滚动视图,您的内容将无法滚动