我在项目中使用Tapku日历。在选择日期的方法
我在视图上显示了另一个视图。这是我的代码
- (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];
}
do on方法显示另一个视图。但点击一个日期后它会显示视图。但之后系统显示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];
}
`
答案 0 :(得分: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并确保你的代码不会泄漏到任何地方。