0

I want to read the value from my DatePicker and store it in my singleton, but I get an exception when trying to do this.

Here is the singleton interface:

@interface Helper : NSObject {
NSMutableArray *array;
//Information For Filter page
NSMutableArray *towns;
NSMutableArray *types;
//Shared resources to apply filters
NSDate *toDate;
NSDate *fromDate;
NSString *selectedType;
NSString *selectedTown;
//Shared resource of which button was clicked
int clicked;
int clickedCell;
int clickedContext;
}
@property (nonatomic, retain) NSMutableArray *array;
@property (nonatomic, retain) NSMutableArray *towns;
@property (nonatomic, retain) NSMutableArray *types;
@property (nonatomic) int clicked;
@property (nonatomic) int clickedCell;
@property (nonatomic) int clickedContext;
@property (nonatomic, retain) NSDate *toDate;
@property (nonatomic, retain) NSDate *fromDate;
@property (nonatomic, retain) NSString *selectedType;
@property (nonatomic, retain) NSString *selectedTown;

+(id)sharedManager;


@end

This is the function where the exception happens

-(void) viewWillDisappear:(BOOL)animated
{

Helper *myHelper = [Helper sharedManager];
if(myHelper.clickedContext == 0)
{
    if(myHelper.clickedCell == 0)
    {
        //causes exception
        myHelper.fromDate = [self.fromDatePicker date];
    }
    else
    {
        //causes exception
        myHelper.toDate = [self.toDatePicker date];
    }
}
else
{
    if(myHelper.clickedCell == 0)
    {
        myHelper.selectedTown = [myHelper.towns objectAtIndex:[self.townPicker selectedRowInComponent:0]];
    }
    else
    {
        myHelper.selectedType = [myHelper.types objectAtIndex:[self.typePicker selectedRowInComponent:0]];
    }
}
[super viewWillDisappear:animated];   
}

declaration of pickers

@property (nonatomic, retain) IBOutlet UIDatePicker *toDatePicker;
@property (nonatomic, retain) IBOutlet UIDatePicker *fromDatePicker;
@property (nonatomic, retain) IBOutlet UIPickerView *typePicker;
@property (nonatomic, retain) IBOutlet UIPickerView *townPicker;

@synthesize part

@synthesize typePicker, toDatePicker, fromDatePicker, townPicker, townsView, toDateView, typesView, fromDateView;

Any idea's why?

Thanks

Armand
  • 9,847
  • 9
  • 42
  • 75

2 Answers2

1

If your outlet is not assigned in interface builder this can happen.

If you think it is, try running the app with NSZombieEnabled = YES and see if you get any error messages.

Joris Mans
  • 6,024
  • 6
  • 42
  • 69
0

I found the problem. In my Helper Class I should have assigned not retained. So it should have been

@property (nonatomic, assign) NSDate *toDate;
@property (nonatomic, assign) NSDate *fromDate;
Armand
  • 9,847
  • 9
  • 42
  • 75
  • 1
    I am not sure that is the correct solution to your problem. When assigning you may be creating a new issue when you go to access them later. – Joe Jul 19 '11 at 15:30
  • @Joe If I do stumble upon more issues regarding this, I will update this. Thanks – Armand Jul 20 '11 at 07:10