Reputation: 2625
Am a newbie to Core Plot & to iOS/Cocoa. I have a view from which am calling another view (called MyGraphView) which has the CorePlot graph.
The MainView.h
@interface MainView : UIViewController { ... }
MainView.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];
....
}
And in the 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;
....
....
In 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];
}
....
....
When this graph view is shown, I also want to show a button below the graph which will take the user to another screen. But I tried various ways to do it, in vain. I tried reducing the graph size using bounds for the frame of the view, in specifying it in 'init' for both the graph and pie chart, in vain. The graph seems to inevitably occupy the entire view. I also tried adding a button in the MyGraphView.xib file (in Interface Builder) but the button doesn't show up when I run the App in iOS Simulator as the graph occupies the entire view/screen.
Any pointers please? I use iOS 5.0 and Xcode 4.2, along with the iOS Simulator to run the App.
Thank you
Upvotes: 0
Views: 550
Reputation: 27381
Don't add the button as a subview of the hosting view. The flip transform used by Core Plot will flip the button, too. Instead, make both the hosting view and button subviews of another view. They can be positioned in the superview like any other views.
Upvotes: 1