2012-10-22 3 views
1

Coreplot API를 사용하여 막대 그래프를 만듭니다. 개별 프로젝트와 동일한 코드를 실행하려고하면 잘 작동하지만 UINavigationController 내 프로젝트에 통합하면 오류가 발생합니다. 반환 dates.count에 [__NSArrayI count] : 할당 취소 된 인스턴스로 전송 된 메시지 0x6dbfd10

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; 
} 

GraphView.m

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

GraphView.h

그것은 나에게 오류를주고있다.

는 [__NSArrayI는 계산] : 0x6dbfd10

답변

7

당신은 오토 릴리즈 객체를 생성하는 할당이 해제 된 인스턴스에 보낸 메시지를. 날짜 배열에 메모리를 할당하십시오.

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]; 
+0

감사 작동 parag :

그런 다음 속성 setter를 사용합니다. 다른 문제가 있습니다. CFDictionary allKeys] : 메시지가 할당 해제 된 인스턴스 0x6ce4dc0으로 전송되었습니다. NSDictionay sets = [NSDictionary dictionaryWithObjectsAndKeys : [UIColor blueColor], @ "Plot 1", [UIColor redColor], @ "Plot 2", [UIColor greenColor], @ "Plot 3", nil] –

+0

NSDictionary 용 메모리를 할당하고 있습니까? –

+0

dictionaryWithObjectsAndKeys도 자동 반복 객체를 만듭니다. NSDictionary에서 @property (nonatomic, retain)를 사용하는 경우 self.sets = [NSDictionary dictionaryWithObjectsAndKeys : [UIColor blueColor], @ "Plot 1", [UIColor redColor], @ "Plot 2", [UIColor greenColor] @ "Plot 3", nil]; 그 외의 경우 set, set = [NSDictionary dictionaryWithObjectsAndKeys : [UIColor blueColor], @ "Plot 1", [UIColor redColor], "Plot 2", [UIColor greenColor], @ "Plot 3", nil]; [보유 설정]; –

2

NSArray * dates 인스턴스 변수를 삭제하십시오. 이것이 속성을 갖는 이유입니다.

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]; 
관련 문제