开发者

EXC_BAD_ACCESS when accessing UIDatePicker

开发者 https://www.devze.com 2023-03-21 03:28 出处:网络
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.

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


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.


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

精彩评论

暂无评论...
验证码 换一张
取 消