2009-10-19 6 views
0

Je reçois l'erreur ci-dessus lors de la compilation d'une application iPhone en utilisant le cadre de base-intrigue. J'ai cette vue de vue de contrôleur liée à un CPLayerHostingView dans IB. Voici l'exemple de code de la fonction viewDidLoad().erreur: demande de membre 'bounds' dans quelque chose pas une structure ou un syndicat

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    graph = [[CPXYGraph alloc] initWithFrame: self.view.bounds]; 

    CPLayerHostingView *hostingView = (CPLayerHostingView *)self.view; 
    hostingView.hostedLayer = graph; 


    graph.paddingLeft = 20.0; 
    graph.paddingTop = 20.0; 
    graph.paddingRight = 20.0; 
    graph.paddingBottom = 20.0; 


    CPXYPlotSpace *plotSpace = (CPXYPlotSpace *)graph.defaultPlotSpace; 
    plotSpace.xRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-6) 
                length:CPDecimalFromFloat(12)]; 
    plotSpace.yRange = [CPPlotRange plotRangeWithLocation:CPDecimalFromFloat(-5) 
                length:CPDecimalFromFloat(30)]; 

    CPLineStyle *lineStyle = [CPLineStyle lineStyle]; 
    lineStyle.lineColor = [CPColor blackColor]; 
    lineStyle.lineWidth = 2.0f; 

    CPXYAxisSet *axisSet = (CPXYAxisSet *)graph.axisSet; 
    axisSet.xAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue]; 
    axisSet.xAxis.minorTicksPerInterval = 4; 
    axisSet.xAxis.majorTickLineStyle = lineStyle; 
    axisSet.xAxis.minorTickLineStyle = lineStyle; 
    axisSet.xAxis.axisLineStyle = lineStyle; 
    axisSet.xAxis.minorTickLength = 5.0f; 
    axisSet.xAxis.majorTickLength = 7.0f; 
    axisSet.xAxis.axisLabelOffset = 3.0f; 

    axisSet.yAxis.majorIntervalLength = [[NSDecimalNumber decimalNumberWithString:@"5"] decimalValue]; 
    axisSet.yAxis.minorTicksPerInterval = 4; 
    axisSet.yAxis.majorTickLineStyle = lineStyle; 
    axisSet.yAxis.minorTickLineStyle = lineStyle; 
    axisSet.yAxis.axisLineStyle = lineStyle; 
    axisSet.yAxis.minorTickLength = 5.0f; 
    axisSet.yAxis.majorTickLength = 7.0f; 
    axisSet.yAxis.axisLabelOffset = 3.0f; 

    CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc] initWithFrame:graph.defaultPlotSpace.bounds] autorelease]; 
    xSquaredPlot.identifier = @"X Squared Plot"; 
    xSquaredPlot.dataLineStyle.lineWidth = 1.0f; 
    xSquaredPlot.dataLineStyle.lineColor = [CPColor redColor]; 
    xSquaredPlot.dataSource = self; 
    [graph addPlot:xSquaredPlot]; 

    CPPlotSymbol *greenCirclePlotSymbol = [CPPlotSymbol ellipsePlotSymbol]; 
    greenCirclePlotSymbol.fill = [CPFill fillWithColor:[CPColor greenColor]]; 
    greenCirclePlotSymbol.size = CGSizeMake(2.0, 2.0); 

    [xSquaredPlot setPlotSymbol:greenCirclePlotSymbol]; 

    CPScatterPlot *xInversePlot = [[[CPScatterPlot alloc] initWithFrame:graph.defaultPlotSpace.bounds] autorelease]; 
    xInversePlot.identifier = @"X Inverse Plot"; 
    xInversePlot.dataLineStyle.lineWidth = 1.0f; 
    xInversePlot.dataLineStyle.lineColor = [CPColor blueColor]; 
    xInversePlot.dataSource = self; 
    [graph addPlot:xInversePlot]; 
} 

Les lignes de trouble sont les suivants:

CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc] initWithFrame:graph.defaultPlotSpace.bounds] autorelease]; 
CPScatterPlot *xInversePlot = [[[CPScatterPlot alloc] initWithFrame:graph.defaultPlotSpace.bounds] autorelease]; 

C'est dit qu'il n'y a pas de 'limites' de graph.defaultPlotSpace. Quelqu'un a-t-il aussi rencontré cela?

Répondre

1

Essayez ces appels avec une syntaxe de parenthèses.

CPScatterPlot *xSquaredPlot = [[[CPScatterPlot alloc] initWithFrame:[[graph defaultPlotSpace] bounds]] autorelease]; 
CPScatterPlot *xInversePlot = [[[CPScatterPlot alloc] initWithFrame:[[graph defaultPlotSpace] bounds]] autorelease]; 
1

Le CPXYPlotSpace vous revenir comme defaultPlotSpace du graphique est une sous-classe de CPPlotSpace, qui est juste une sous-classe de NSObject. Aucune de ces classes ne définit une propriété bounds. Au lieu de cela, CPXYPlotSpace a défini des plages via les objets CPPlotRange, comme vous le voyez dans les deux premières lignes après avoir récupéré le defaultPlotSpace.

La bonne façon de faire ce que vous voulez serait d'allouer les tracés et d'utiliser simplement -init, plutôt que -initWithFrame :. Lorsque ces graphiques sont ajoutés au graphique, je crois qu'ils sont automatiquement dimensionnés en fonction de l'espace de tracé. Alternativement, vous pouvez utiliser -initWithFrame: et utiliser l'image du graphique.

Si vous souhaitez voir une méthode pratique qui renvoie les limites d'un CPXYPlotSpace, faites-le nous savoir dans le mailing list.

+0

Merci pour l'info, Brad. Je vais aller avec votre suggestion ici. J'ai essentiellement fait une copie/coller directement à partir du switchonthecode.com, et je suis revenu avec ces erreurs. La méthode de commodité serait bien, mais probablement inutile si je peux attraper le cadre de l'objet graphique à la place. –

+0

Malheureusement, l'API sur le framework est toujours en évolution, donc l'exemple switchonthecode.com ne fonctionne plus dès la sortie de la boîte avec la version actuelle du framework. Quelques légers ajustements sont nécessaires pour l'aligner sur l'API actuelle. Désolé pour ça. –

0

Le problème de cette erreur est résolu en ajoutant un framework Quartzcore s'il n'est pas inclus.

Questions connexes