I want to set datePicker for birthdate selection but it give EXC_BAD_ACCESS
.I did init picker in EditProfileViewController.h
file as
@property (nonatomic,retain) UIDatePicker *datePicker;
and used in EditProfileViewController.m
as
NSCalendar * calendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
NSDate * currentDate = [NSDate date];
NSDateComponents * comps = [[NSDateComponents alloc] init];
NSDate * maxDate = [calendar dateByAddingComponents: comps toDate: currentDate options: 0];
[comps setYear: -150];
NSDate * minDate = [calendar dateByAddingComponents: comps toDate: currentDate options: 0];
self.datePicker = [[UIDatePicker alloc] initWithFrame: CGRectMake(0, 200, [UIScreen mainScreen].bounds.size.width, 216)];
self.datePicker.datePickerMode = UIDatePickerModeDate;
self.datePicker.calendar = calendar;
[self.datePicker setMaximumDate: maxDate];
[self.datePicker setMinimumDate: minDate];
self.datePicker.date = maxDate;
But it crash on line self.datePicker.datePickerMode = UIDatePickerModeDate;
I also did check for nullability as
if(self.datePicker == nil){
self.datePicker = [[UIDatePicker alloc] initWithFrame: CGRectMake(0, 200, [UIScreen mainScreen].bounds.size.width, 216)];
}
before setting datePickerMode,but same result (:
As given in this article When EXC_BAD_ACCESS happen?
You will get EXC_BAD_ACCESS in 3 cases:
- An object is not initialized
- An object is already released
- Something else that is not very likely to happen
In my case its 3rd step(Something else that is not very likely to happen.)
I checked similar answer where it says to Enable Zombie Objects
.
Then enabled Zombie Objects as given in How to enable NSZombie in Xcode? and How to debug EXC_BAD_ACCESS with NSZombie in XCode 5 with no success.
So the question is how to solve/debug this type of issue?
Note: it's working on ios8.3 simulator,And the problem is in iPhone 4 - ios 7