weilsonwonder / WWCalendarTimeSelector

A android inspired iOS date/time picker
MIT License
317 stars 126 forks source link

fatal error: unexpectedly found nil while unwrapping an Optional value #9

Closed dhekrazaied closed 8 years ago

dhekrazaied commented 8 years ago

when use the code with ios project with objective c and I get this error fatal error: unexpectedly found nil while unwrapping an Optional value this is my code -(IBAction)goToPickerDateTime:(id)sender{

self.selectorCal = [[WWCalendarTimeSelector alloc]init];
self.selectorCal.delegate = self;
self.selectorCal.optionCurrentDate = self.singleDate;
self.selectorCal.optionCurrentDates = self.multipleDates;
[self.selectorCal.optionStyles showDateMonth:true];
[self.selectorCal.optionStyles  showMonth:false];
[self.selectorCal.optionStyles showYear:false ];
[self.selectorCal.optionStyles showTime:false];
[self.selectorCal.optionCurrentDateRange setStartDate :   self.singleDate ];
[self.selectorCal.optionCurrentDateRange setEndDate:   self.singleDate];
[self presentViewController:self.selectorCal animated:YES completion:nil];

}

weilsonwonder commented 8 years ago

Hi, please try init by calling the designated instantiate() method instead of alloc()init()

Something like [WWCalendarTimeSelector instantiate];

dhekrazaied commented 8 years ago

same error fatal error: unexpectedly found nil while unwrapping an Optional value

weilsonwonder commented 8 years ago

Hi @dhekrazaied

Perhaps you could try this because I'm not having any issues with it (:

#import "ViewController.h"
#import <WWCalendarTimeSelector/WWCalendarTimeSelector-Swift.h>

@interface ViewController () <WWCalendarTimeSelectorProtocol>

@property (strong, nonatomic) NSDate *singleDate;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    self.singleDate = [NSDate new];
}

- (IBAction)openCalendar:(id)sender {
    WWCalendarTimeSelector *cal = [WWCalendarTimeSelector instantiate];
    cal.delegate = self;
    cal.optionCurrentDate = self.singleDate;
    [cal.optionStyles showDateMonth:true];
    [cal.optionStyles  showMonth:false];
    [cal.optionStyles showYear:false ];
    [cal.optionStyles showTime:false];
    [cal.optionCurrentDateRange setStartDate :   self.singleDate ];
    [cal.optionCurrentDateRange setEndDate:   self.singleDate];
    [self presentViewController:cal animated:YES completion:nil];
}

- (void)WWCalendarTimeSelectorDone:(WWCalendarTimeSelector *)selector date:(NSDate *)date {
    self.singleDate = date;
}

@end
dhekrazaied commented 8 years ago

I think I have a problem in the .storyboard file not in the code

weilsonwonder commented 8 years ago

Hi, please explain in detail what happens to storyboard file. I'm having no issues on my side by creating a new objective c project, and installing the library through cocoapods (:

dhekrazaied commented 8 years ago

I didn't use cocopods I just add folder and files, and I modified the target of wwcalendertimeselector.storyboard in the inspector from wwcalendertimeselector to the current project

weilsonwonder commented 8 years ago

Hi, apologies for the inconvenience. The problem (happened in another issue) was the Module in custom class. It's supposed to be empty (so that it's default), and not pointing to WWCalendarTimeSelector.

screen shot 2016-08-16 at 8 36 58 pm screen shot 2016-08-16 at 8 36 52 pm
weilsonwonder commented 8 years ago

The UIViewController itself might be pointing to the same WWCalendarTimeSelector. Do delete the defined module, and it should work.

dhekrazaied commented 8 years ago

thx a lot it's work perfectly now. Best regards.

vishaldeshai commented 7 years ago

Is it chances to crash app.

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"WWCalendarTimeSelector" bundle:nil];

WWCalendarTimeSelector *selector = (WWCalendarTimeSelector *)[storyboard instantiateInitialViewController];

selector.delegate = self;

[selector.optionStyles showDateMonth:YES];
[selector.optionStyles showMonth:NO];
[selector.optionStyles showYear:NO];
[selector.optionStyles showTime:NO];
selector.optionCurrentDate = leftDate;
selector.optionIdentifier = @"1";
[self presentViewController:selector animated:YES completion:nil];

thanks in advance.