我是 Core Plot 和 iOS/Cocoa 的新手。我有一个视图,它正在调用另一个具有 CorePlot 图的视图(称为 MyGraphView)。
MainView.h
@interface MainView : UIViewController { ... }
主视图.m
....
....
@implementation MyView
....
MyGraphView *myGraphView;
....
....
// This gets called when a button's pressed. Once the button's pressed,
// I want to display the view which has the graph i.e. pie chart
-(IBAction) toDateChosen:(id)sender {
....
[self presentModalViewController:myGraphView animated:YES];
....
}
....
....
- (void)viewDidLoad {
...
myGraphView = [[EmotionsHistoryView alloc] initWithNibName:nil bundle:nil];
....
}
在 MyGraphView.h
#import <UIKit/UIKit.h>
#import "CorePlot-CocoaTouch.h"
@interface MyGraphView : UIViewController <CPTPlotDataSource> {
....
....
CPTXYGraph *graph;
CPTPieChart *pieChart;
}
@property (nonatomic, retain) CPTXYGraph *graph;
-(void) initializeGraph;
-(void) initializePieChart;
....
....
在 MyGraphView.m
....
@implementation MyGraphView
....
-(void) initializeGraph {
graph = [[CPTXYGraph alloc] initWithFrame:CGRectZero];
CPTGraphHostingView *hostingView = (CPTGraphHostingView *)self.view;
hostingView.hostedGraph = graph;
//hostingView.bounds = CGRectMake(5, 5, 70, 70);
[self initializePieChart];
}
....
....
-(void) initializePieChart {
pieChart = [[CPTPieChart alloc] initWithFrame:CGRectMake(25, 25, 50, 20)];
pieChart.dataSource = self;
pieChart.pieRadius = 100.0;
pieChart.opaque = FALSE;
pieChart.pieRadius = 60;
pieChart.shadowOffset = CGSizeMake(-1, 1);
pieChart.identifier = @"Identifier1";
pieChart.startAngle = M_PI_4;
pieChart.sliceDirection = CPTPieDirectionCounterClockwise;
pieChart.labelOffset = -0.6;
[graph addPlot:pieChart];
}
....
....
当显示此图表视图时,我还想在图表下方显示一个按钮,该按钮会将用户带到另一个屏幕。但是我尝试了各种方法来做到这一点,但徒劳无功。我尝试使用视图框架的边界来减小图形大小,在图形和饼图的“init”中指定它,但徒劳无功。图表似乎不可避免地占据了整个视图。我还尝试在 MyGraphView.xib 文件中添加一个按钮(在 Interface Builder 中),但是当我在 iOS 模拟器中运行应用程序时,该按钮没有显示,因为图形占据了整个视图/屏幕。
请问有什么指点吗?我使用 iOS 5.0 和 Xcode 4.2 以及 iOS 模拟器来运行应用程序。
谢谢