2010-09-15 5 views
2

Je tente de charger un CPXYGraph dans la vue détaillée d'un contrôleur de vue éclatée. J'obtiens un EXC_BAD_ACCESS quand il essaie d'afficher les données de tracé.Vue détaillée de l'intérieur de la vue partagée CorePlot

Je crée un nouveau projet basé sur "Split View-based application". Après avoir ajouté l'infrastructure CorePlot, j'apporte les modifications suivantes:

1- ajoutez un GraphController (.m, .h et .xib). Le xib contient un UIView avec une vue subordonnée de type CPLayerHostingView. 2- ajouter la ligne suivante au délégué app didFinishLaunchingWithOptions

[detailViewController performSelector:@selector(configureView) withObject:nil afterDelay:0]; 

3- ajouter ce qui suit à DetailViewController configureView

CGRect graphFrame = CGRectMake(0, 43, 662, 450); 
GraphController *graphController = [[[GraphController alloc] 
    initWithNibName:@"GraphController" bundle:nil] autorelease]; 
[graphController.view setFrame:graphFrame]; 
[self.view addSubview:graphController.view]; 
[graphController reloadData]; 

4- la méthode reloadData dans GraphController est assez bien collé à partir d'un des CorePlot (échantillons DatePlot) et je copier et coller (la plupart), il ici-

-(void)reloadData 
{ 
    if (!graph) 
    { 
     [self parentViewController]; 
     [self.view addSubview:layerHost]; 

     // Create graph from theme 
     graph = [[CPXYGraph alloc] initWithFrame:CGRectZero]; 
     CPTheme *theme = [CPTheme themeNamed:@"Dark Gradients"]; 
     [graph applyTheme:theme]; 
     .... 
     [layerHost setHostedLayer: graph]; 
     .... 
     // Setup scatter plot space 
     CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace; 
     NSTimeInterval xLow = 0.0f; 
     plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(xLow) length:CPDecimalFromFloat(oneDay*5.0f)]; 
     plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(1.0) length:CPDecimalFromFloat(3.0)]; 

     // Axes 
     CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet; 
     CPXYAxis *x = axisSet.xAxis; 
     x.majorIntervalLength = CPDecimalFromFloat(oneDay); 
     x.orthogonalCoordinateDecimal = CPDecimalFromString(@"2"); 
     x.minorTicksPerInterval = 0; 
     NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; 
     dateFormatter.dateStyle = kCFDateFormatterShortStyle; 
     CPTimeFormatter *timeFormatter = [[[CPTimeFormatter alloc] initWithDateFormatter:dateFormatter] autorelease]; 
     timeFormatter.referenceDate = refDate; 
     x.labelFormatter = timeFormatter; 

     CPXYAxis *y = axisSet.yAxis; 
     y.majorIntervalLength = CPDecimalFromString(@"0.5"); 
     y.minorTicksPerInterval = 5; 
     y.orthogonalCoordinateDecimal = CPDecimalFromFloat(oneDay); 

     // Create a plot that uses the data source method 
     CPScatterPlot *dataSourceLinePlot = [[[CPScatterPlot alloc] init] autorelease]; 
     dataSourceLinePlot.identifier = @"Date Plot"; 
     dataSourceLinePlot.dataLineStyle.lineWidth = 3.f; 
     dataSourceLinePlot.dataLineStyle.lineColor = [CPColor greenColor]; 
     dataSourceLinePlot.dataSource = self; 
     **[graph addPlot:dataSourceLinePlot];** 

     // Add some data 
     NSMutableArray *newData = [NSMutableArray array]; 
     NSUInteger i; 
     for (i = 0; i < 5; i++) { 
      NSTimeInterval x = oneDay*i; 
      id y = [NSDecimalNumber numberWithFloat:1.2*rand()/(float)RAND_MAX + 1.2]; 
      [newData addObject: 
      [NSDictionary dictionaryWithObjectsAndKeys: 
       [NSDecimalNumber numberWithFloat:x], [NSNumber numberWithInt:CPScatterPlotFieldX], 
       y, [NSNumber numberWithInt:CPScatterPlotFieldY], 
       nil]]; 
     } 
     plotData = newData; 
    } 
} 

La ligne incriminée est un graphique [a ddPlot: dataSourceLinePlot]; Si je commente cela, le simulateur apparaît et affiche les axes x et y du graphique et, bien sûr, aucune donnée. L'ajout de cette ligne provoque les événements suivants SIGART-

2010-09-15 14:35:58.959 SplitViewWithCorePlot[17301:207] relabel <<CPScatterPlot: 0x4c458c0> bounds: {{0, 0}, {558, 386}}> 
Program received signal: “EXC_BAD_ACCESS”. 

Quelqu'un peut-il aider?

Répondre

0

Il ne semble pas que vous conserviez le tableau de données n'importe où. Essayez de changer la dernière déclaration à

plotData = [newData retain]; 

ou, si vous avez une propriété définie pour elle,

self.plotData = newData; 

Eric

+0

n'a pas fonctionné. Même problème. – DLS

+0

Je cours le même code (CP) dans un projet sans Split View et cela fonctionne. Je voudrais vraiment avoir la vue de Split comme option cependant. – DLS

Questions connexes