0

I am using Tapku calendar on my project .In the method for selecting a date

i showed another view on the view.Here is my code

- (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];

}

the do on method shows another view. But after clicking a date it shows the view .But after that the system shows EXC_BAD_ACCESS.Any ideas.. I am trying but cant find the error . Please i need help

Here is the code for the methods above:::::::

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


}               

This is the initWithTimeCards method

    -(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];



}

`

Masud alam
  • 69
  • 10
  • 1
    Could you put your code into the code tags? – Wesley Oct 31 '11 at 12:20
  • It's odd that you have an init called twice on your dataController object. Is this intentional? Perhaps there is a memory corruption in calling it twice. – AWF4vk Oct 31 '11 at 14:43
  • Thanks david for pointing that out.Maybe it is the error .I was allocating because at the first phase of the project i didnt call the init method twice.I did not allocate the object on the load view method. But later i did just that and forgot to remove that statement. – Masud alam Oct 31 '11 at 15:07

1 Answers1

0

Try enabling NSZombies to see which object that's being over-released (that's likely to be your issue).

See How do I set up NSZombieEnabled in Xcode 4? for instructions on how to enable it.

EDIT: Also, make sure to check the -initWithTimeCards and -getTimeCardWithStartData:endDate:timeCardType methods to see if you're over-releasing something in there.

EDIT 2: The issue is probably that some of your arrays isn't retained properly in memory. Try changing fetchedSyncedTimeCards to self.fetchedSyncedTimeCards and do the same with fetchedNotSyncedTimeCards. You're probably returning an autoreleased object in -fetchTimceCardWithSyncStatus and not retaining it afterwards, causing your program to invoke methods on an object that is no longer allocated.

But even if it works, you should really read up on memory management and make sure your code doesn't leak everywhere.

Community
  • 1
  • 1
Kristofer Sommestad
  • 3,061
  • 27
  • 39
  • i have enabled NSZombies and malloc history .But nothing shows up in the debugger. The stack trace from the debugger is following [objc msgsend]; -performRunloopAction -CFRunloop-IS-Calling-out-to-an-observer callback function – Masud alam Oct 31 '11 at 12:41
  • OK, and you're not seeing any reference to the over-released object or a method in your own class? Could you post the code of the other methods as well (the ones I mentioned in the edit)? – Kristofer Sommestad Oct 31 '11 at 12:51
  • Thanks. Are you using ARC (Automatic Reference Counting? If you're not using ARC, your code's leaking pretty much everywhere, as you're increasing the retain count but never decreasing it. But as you're not sending any `release` messages whatsoever, I can't really see what could be over-released. Would you mind posting the stacktrace you're getting? And have you tried setting a symbolic breakpoint to see at which row it crashes (http://stackoverflow.com/questions/384775/how-do-i-find-out-what-exception-was-thrown-in-the-xcode-debugger-for-iphone)? – Kristofer Sommestad Oct 31 '11 at 13:40
  • ... and depending on how your properties are set up, you could be getting errors on `fetchedSyncedTimeCards = ...` and `fetchedNotSyncedTimeCards = ...`, as they're not explicitly retained (or set through a setter method). – Kristofer Sommestad Oct 31 '11 at 13:42
  • NO i havnt done any of it. I am new to ios programming .I am posting my stack trace .And thanks for your time – Masud alam Oct 31 '11 at 14:24
  • [objc msgsend]; ?? -performRunloopAction -CFRunloop-IS-Calling-out-to-an-observer callback function – Masud alam Oct 31 '11 at 14:52
  • OK, you should really read up on Memory management then (http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/MemoryMgmt.html) and make sure you follow the policies. Please see the 2nd edit in my post. – Kristofer Sommestad Oct 31 '11 at 15:31
  • Thanks Kristofer now my problem is solved according to your advice. – Masud alam Nov 01 '11 at 09:39