2011-10-31 67 views
0

我使用Tapku日曆上我的項目。在方法選擇的日期EXC BAD訪問錯誤

我發現在view.Here另一種觀點是我的代碼

- (void)calendarMonthView:(TKCalendarMonthView *)monthView didSelectDate:(NSDate *)date { 

    self.dataController=[[TimeCardDataController alloc] init]; 
    self.dataController.managedObjectContext=[self context]; 
    [self.dataController initWithTimeCards]; 

    NSDate *weekStartDay=[date weekFirstDate]; 
    NSDate *weekEndDay=[date weekLastDate]; 
    self.billdailyValuePositiveArray= [self.dataController getTimeCardWithStartData:date endDate:date timeCardType:TIMECARD_STATUS_BILLABLE]; 
    self.billweeklyValueNegetiveArray= [self.dataController getTimeCardWithStartData:weekStartDay endDate:weekEndDay timeCardType:TIMECARD_STATUS_NONBILLABLE]; 
    self.billweeklyValuePositiveArray= [self.dataController getTimeCardWithStartData:weekStartDay endDate:weekEndDay timeCardType:TIMECARD_STATUS_BILLABLE]; 
    self.billdailyValueNegetiveArray= [self.dataController getTimeCardWithStartData:date endDate:date timeCardType:TIMECARD_STATUS_NONBILLABLE]; 

    self.syncweeklyValuePositiveArray=[self.dataController getTimeCardWithStartData:weekStartDay endDate:weekEndDay timeCardType:TIMECARD_STATUS_SYNCED]; 
    self.syncweeklyValueNegetiveArray=[self.dataController getTimeCardWithStartData:weekStartDay endDate:weekEndDay timeCardType:TIMECARD_STATUS_NOTSYNCED]; 
    self.syncdailyValuePositiveArray= [self.dataController getTimeCardWithStartData:date endDate:date timeCardType:TIMECARD_STATUS_SYNCED]; 
    self.syncdailyValueNegetiveArray= [self.dataController getTimeCardWithStartData:date endDate:date timeCardType:TIMECARD_STATUS_NOTSYNCED]; 

    self.postweeklyValuePositiveArray= [self.dataController getTimeCardWithStartData:weekStartDay endDate:weekEndDay timeCardType:TIMECARD_STATUS_POSTED]; 
    self.postweeklyValueNegetiveArray= [self.dataController getTimeCardWithStartData:weekStartDay endDate:weekEndDay timeCardType:TIMECARD_STATUS_NOTPOSTED]; 
    self.postdailyValuePositiveArray= [self.dataController getTimeCardWithStartData:date endDate:date timeCardType:TIMECARD_STATUS_POSTED]; 
    self.postdailyValueNegetiveArray= [self.dataController getTimeCardWithStartData:date endDate:date timeCardType:TIMECARD_STATUS_NOTPOSTED]; 


    [self toggleCalendar]; 

    [self doOn:date]; 

} 

的方法做顯示另一種觀點。但點擊日期後,它會顯示視圖。但在此之後,系統顯示EXC_BAD_ACCESS.Any想法..我正在嘗試但無法找到該錯誤。請我需要幫助

這裏是上述:::::::方法的代碼

-(NSMutableArray *) getTimeCardWithStartData:(NSDate *) startDate endDate:(NSDate *)endDate timeCardType:(NSString *) timeCardType 
{ 
    NSMutableArray* timeCardArray=[[NSMutableArray alloc] init]; 

    NSMutableArray *categoryTimeCardArray=[[NSMutableArray alloc] init] ; 
    if ([timeCardType isEqualToString:TIMECARD_STATUS_BILLABLE]) 
    { 
     categoryTimeCardArray=[self fetchedTimeCardWithStartDate:startDate endDate:endDate fetchedCategoryTimeCard:self.fetchedBillableTimeCards]; 

    } 
    else if([timeCardType isEqualToString:TIMECARD_STATUS_NONBILLABLE]) 
    { 
     categoryTimeCardArray=[self fetchedTimeCardWithStartDate:startDate endDate:endDate fetchedCategoryTimeCard:self.fetchedNonBillableTimeCards]; 

    } 
    else if ([timeCardType isEqualToString:TIMECARD_STATUS_POSTED]) 
    { 
     categoryTimeCardArray=[self fetchedTimeCardWithStartDate:startDate endDate:endDate fetchedCategoryTimeCard:self.fetchedPostedTimeCards]; 

    } 
    else if([timeCardType isEqualToString:TIMECARD_STATUS_NOTPOSTED]) 
    { 
     categoryTimeCardArray=[self fetchedTimeCardWithStartDate:startDate endDate:endDate fetchedCategoryTimeCard:self.fetchedNotPostedTimeCards]; 

    } 
    else if([timeCardType isEqualToString:TIMECARD_STATUS_SYNCED]) 
    { 
     categoryTimeCardArray=[self fetchedTimeCardWithStartDate:startDate endDate:endDate fetchedCategoryTimeCard:fetchedSyncedTimeCards]; 

    } 

    else if ([timeCardType isEqualToString:TIMECARD_STATUS_NOTSYNCED]) 
    { 
     categoryTimeCardArray=[self fetchedTimeCardWithStartDate:startDate endDate:endDate fetchedCategoryTimeCard:fetchedNotSyncedTimeCards]; 

    } 





    return categoryTimeCardArray; 


}    

這是initWithTimeCards方法

-(void) initWithTimeCards 
{ 
    [self fetchAllTimeCard]; 
    fetchedTimecards=[[NSArray alloc] init]; 
    fetchedBillableTimeCards=[[NSArray alloc] init]; 
    fetchedBillableTimeCards=[[NSArray alloc] init]; 
    self.fetchedNonBillableTimeCards =[[NSArray alloc] init]; 
    self.fetchedPostedTimeCards=[[NSArray alloc] init]; 
    self.fetchedNotPostedTimeCards=[[NSArray alloc] init]; 
    fetchedSyncedTimeCards=[[NSArray alloc] init]; 
    fetchedNotSyncedTimeCards=[[NSArray alloc] init]; 



    self.fetchedNonBillableTimeCards =[self fetchTimceCardWithBillStatus:TIMECARD_BILL_STATUS_NONBILLABLE]; 
    self.fetchedPostedTimeCards=[self fetchTimceCardWithPostStatus:TIMECARD_BILL_STATUS_POSTED]; 
    self.fetchedNotPostedTimeCards=[self fetchTimceCardWithPostStatus:TIMECARD_BILL_STATUS_NOTPOSTED]; 
    fetchedSyncedTimeCards=[self fetchTimceCardWithSyncStatus:TIMECARD_BILL_STATUS_SYNCED]; 
    fetchedNotSyncedTimeCards=[self fetchTimceCardWithSyncStatus:TIMECARD_BILL_STATUS_NOTSYNCED]; 



} 

`

+1

你可以把你的代碼放入代碼標籤嗎? – Wesley

+0

奇怪的是,你有一個在你的dataController對象上調用兩次的init。這是故意的嗎?也許在調用它兩次時存在內存損壞。 – David

+0

謝謝大衛指出了。也許這是錯誤。我分配,因爲在項目的第一階段,我沒有調用init方法兩次。我沒有分配負載視圖方法的對象。但後來我只是這樣做了,忘了刪除那個聲明。 –

回答

0

嘗試啓用NSZombies看看哪個對象被過度釋放(這可能是你的問題)。

有關如何啓用它的說明,請參閱How do I set up NSZombieEnabled in Xcode 4?

編輯:此外,請務必檢查-initWithTimeCards-getTimeCardWithStartData:endDate:timeCardType方法,看看你過度釋放在那裏的東西。

編輯2:問題可能是您的某些數組在內存中沒有正確保留。嘗試將fetchedSyncedTimeCards更改爲self.fetchedSyncedTimeCards,然後對fetchedNotSyncedTimeCards執行相同操作。您可能在-fetchTimceCardWithSyncStatus中返回一個自動釋放對象,並且之後不保留它,導致您的程序在不再分配的對象上調用方法。

但即使它工作,你應該真的read up on memory management,並確保你的代碼不泄漏到處。

+0

我已經啓用了NSZombies和malloc的歷史。但沒有在調試器中顯示出來。調試器的堆棧跟蹤如下[objc msgsend]; -performRunloopAction -CFRunloop-IS-Call-out-to-an-observer回調函數 –

+0

好的,你沒有看到對你自己的類中過度釋放的對象或方法的任何引用? 你可以發佈其他方法的代碼(我在編輯中提到的那些代碼)? –

+0

:我已經添加了兩種方法的代碼 –