0

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:

  1. An object is not initialized
  2. An object is already released
  3. 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

Community
  • 1
  • 1
Giru Bhai
  • 14,370
  • 5
  • 46
  • 74
  • may be you forgot to set minDate..... – Ram Vinay Yadav Sep 02 '15 at 07:21
  • I did as in `[self.datePicker setMinimumDate: minDate]` and it crash before setting date at line `self.datePicker.datePickerMode = UIDatePickerModeDate;` – Giru Bhai Sep 02 '15 at 07:22
  • Post also the crash stack trace – Lefteris Sep 02 '15 at 07:37
  • I got EXC_BAD_ACCESS,and unable to get log.please tell me how to get log for EXC_BAD_ACCESS? – Giru Bhai Sep 02 '15 at 07:38
  • @Lefteris did try http://stackoverflow.com/questions/19740200/how-to-debug-exc-bad-access-bug but did not get any log. – Giru Bhai Sep 02 '15 at 07:43
  • Any reason why you don't use ARC (since there is "retain" instead of "strong")? If you comment the line, does it still crash? Did you try this: http://natashatherobot.com/xcode-debugging-trick/ ? – Larme Sep 02 '15 at 15:48
  • @Larme changed from `retain` to `strong` with no success. and also try to find out crash as given link(by you) but unable to find `objc_exception_throw` in my Thread. Is there any other methods to find `objc_exception_throw` in thread? Anyway thanks. – Giru Bhai Sep 03 '15 at 07:16

0 Answers0