1

I am using the Coreplot API to create a bar graph. When I try to run this same code as an individual project it's working fine but when I integrate it to my project inside UINavigationController it is giving me an error.

GraphView.h

    @interface GraphView : CPTGraphHostingView <CPTPlotDataSource, CPTPlotSpaceDelegate>
   {
    CPTXYGraph *graph;
    NSArray *dates; 
   } 
  @property(nonatomic, retain) NSArray *dates;

GraphView.m

dates = [NSArray arrayWithObjects:@"2012-05-01", @"2012-05-02", @"2012-05-03", 
             @"2012-05-04", @"2012-05-05", @"2012-05-06", @"2012-05-07", @"2012-05-08", @"2012-05-09",@"2012-05-10",@"2012-05-11",@"2012-05-12",@"2012-05-13",@"2012-05-14",@"2012-05-15",@"2012-05-16",@"2012-05-17",@"2012-05-18",@"2012-05-19",@"2012-05-20",nil];


 - (NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plot
{
    return dates.count;
}

On return dates.count it is giving me the error.

[__NSArrayI count]: message sent to deallocated instance 0x6dbfd10

4

2 に答える 2

7

You are creating an autorelease object. Allocate memory to dates array.

dates =    [[NSArray alloc]initWithObjects:@"2012-05-01", @"2012-05-02", @"2012-05-03", 
                 @"2012-05-04", @"2012-05-05", @"2012-05-06", @"2012-05-07", @"2012-05-08", @"2012-05-09",@"2012-05-10",@"2012-05-11",@"2012-05-12",@"2012-05-13",@"2012-05-14",@"2012-05-15",@"2012-05-16",@"2012-05-17",@"2012-05-18",@"2012-05-19",@"2012-05-20",nil];
于 2012-10-22T07:13:28.657 に答える
2

Drop the NSArray *dates instance variable - that's why you have the property, it makes that for you.

Then use the property setter:

self.dates = [NSArray arrayWithObjects:@"2012-05-01", @"2012-05-02", @"2012-05-03", 
             @"2012-05-04", @"2012-05-05", @"2012-05-06", @"2012-05-07", @"2012-05-08", @"2012-05-09",@"2012-05-10",@"2012-05-11",@"2012-05-12",@"2012-05-13",@"2012-05-14",@"2012-05-15",@"2012-05-16",@"2012-05-17",@"2012-05-18",@"2012-05-19",@"2012-05-20",nil];
于 2012-10-22T07:18:37.730 に答える