iOSプログラミングとCore Plotの初心者です。 XCode 4.2とiOS 5を使って、iOS Simulatorを使ってiPhone Appをテストしていますか?Core Plot円グラフをサブビューとして追加する - 円グラフが描画されない
私はここで何かを見落としていることを知っています(&は多くのgoogle'ingを試してみました。&はいろいろな解決策を試してみました)。誰かが助けてくれるの?
非常に簡単なことをしようとしています - >(Core Plotを使って行われた)円グラフをサブビューとして追加しています。最初は円グラフをモーダル表示&として表示していましたが、うまくいきました。今、同じビューでいくつかのボタンを追加したいので、ボタンを押して表示されるビューを作成し、2つのボタンを追加してこの円グラフを追加しようとしました。ボタンはうまく表示されますが、円グラフは表示されません!
これは、押されたボタンのときに表示されます「GraphView」と呼ばれるビューのXIBファイルです:上のスクリーンショットで
、強調表示ビュー「表示」は、その中のUIViewオブジェクトであります私は円グラフを表示したい。ビュー 'GraphView'全体が表示されます。 2つのボタンが表示されますが、サブビューに追加した円グラフは表示されません。上の図でサブビューとして追加したUIViewオブジェクトも表示されます(背景色を設定してチェックしました)。これはコードです:
GRAPHVIEW.H
#import <UIKit/UIKit.h>
#import "PieChartView.h"
@interface GraphView : UIViewController
@property (strong, nonatomic) PieChartView *pieChartView;
// gView is the view which is linked to the 'UIView' subview in IB
// in the above figure
@property (strong, nonatomic) IBOutlet UIView *gView;
@property (strong, nonatomic) IBOutlet UIButton *buttonBack;
@property (strong, nonatomic) IBOutlet UIButton *buttonMail;
-(void) setHistoryData:(NSArray *)history;
...
...
@end
GRAPHVIEW.M
...
...
@synthesize gView;
@synthesize buttonBack;
@synthesize buttonMail;
...
...
-(void) setHistoryData:(NSArray *)history {
NSLog(@"GraphView: setHistoryData");
[pieChartView setHistoryData:history];
[gView addSubview:pieChartView];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
pieChartView = [[PieChartView alloc] init];
return self;
}
...
...
の#pragmaマーク - ビューのライフサイクル
- (void)viewDidLoad
{
NSLog(@"GraphView: viewDidLoad");
[super viewDidLoad];
[pieChartView initializeGraph];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
PIECHARTVI EW.H これは、円グラフを描画すると思われるものです。
#import <UIKit/UIKit.h>
#import "CorePlot-CocoaTouch.h"
// I tied subclassing 'UIViewController' or just 'UIView'...all in vain
@interface PieChartView : CPTGraphHostingView <CPTPlotDataSource> {
CPTXYGraph *graph;
CPTPieChart *pieChart;
}
@property (nonatomic, retain) CPTXYGraph *graph;
-(void) initializeGraph;
-(void) initializePieChart;
-(void) setHistoryData:(NSArray *)history;
@end
PIECHARTVIEW.m
...
@implementation PieChartView
@synthesize graph;
NSArray *historyData;
// I added the NSLog to see if these get called, but they don't seem to get called!
// So, this means that the pie chart is not being drawn actually!
-(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot {
NSLog(@"numberOfRecordsForPlot: History count: %d", (int)[historyData count]);
return [historyData count];
}
// This too isn't getting called
-(NSNumber *) numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index {
NSLog(@"historyView: numberForPlot");
return [historyData objectAtIndex:index];
}
// This too is not getting called! OMG!
-(CPTLayer *)dataLabelForPlot:(CPTPlot *)plot recordIndex:(NSUInteger)index {
NSLog(@"HistoryView: dataLabelForPlot");
...
}
// This method is getting called. Am seeing the log messages
-(void) initializeGraph {
NSLog(@"HistoryView: initializeGraph");
graph = [[CPTXYGraph alloc] init];
CPTTheme *theme = [CPTTheme themeNamed:kCPTDarkGradientTheme];
[graph applyTheme:theme];
CPTGraphHostingView *hostingView = (CPTGraphHostingView *) self;
hostingView.hostedGraph = graph;
//hostingView.bounds = CGRectMake(5, 5, 70, 70);
[self initializePieChart];
}
// This method is also getting called. I see the log messages from this method too
/**
* Initialize the pie chart for display
*/
-(void) initializePieChart {
NSLog(@"HistoryView: initializePieChart");
pieChart = [[CPTPieChart alloc] init];
pieChart.dataSource = self;
pieChart.pieRadius = 100.0;
pieChart.opaque = FALSE;
//pieChart.pieRadius = 60;
pieChart.shadowOffset = CGSizeMake(-1, 1);
pieChart.identifier = @"PieChart";
pieChart.startAngle = M_PI_4;
pieChart.sliceDirection = CPTPieDirectionCounterClockwise;
pieChart.labelOffset = -0.6;
[graph addPlot:pieChart];
NSLog(@"added pie chart to the graph view");
}
// This also is getting called
-(void) setHistoryData:(NSArray *)history {
NSLog(@"HistoryView: setHistoryData");
historyData = history;
}
...
...
@end
恐ろしく!百万、エリックありがとう! :) ワオ!それは動作します!ありがとう:)(OMG ...これで苦労して2日後!それは働くのがすごく素晴らしいと感じています!) – Jean