cordova datepicker plugin not working in iOS8: UITableView dataSource is not set

michael

after updated to iOS8, the cordova datepicker plugin not work. it crashed with following message:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource is not set'

but i don't see any UITableView related code in the plugin source code. i don't know, maybe there is an internal UITableView in the UIDatePicker?

here is the code(i remove some non-relative code for easy reading):

- (UIPopoverController *)createPopover:(NSMutableDictionary *)options {

  UIView *datePickerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, pickerViewWidth, pickerViewHeight)];

  if(!self.datePicker){
    self.datePicker = [self createDatePicker:options frame:frame];
    [self.datePicker addTarget:self action:@selector(dateChangedAction:) forControlEvents:UIControlEventValueChanged];
  }

  NSDateFormatter *formatter = [self createISODateFormatter:@"yyyy-MM-dd'T'HH:mm:ss'Z'" timezone:[NSTimeZone defaultTimeZone]];
  NSString *dateString = [options objectForKey:@"date"];
  self.datePicker.date = [formatter dateFromString:dateString];// if remove this line, it works fine

  [datePickerView addSubview:self.datePicker];

  UIViewController *datePickerViewController = [[UIViewController alloc]init];
  datePickerViewController.view = datePickerView;

  UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:datePickerViewController];
  popover.delegate = self;
  [popover setPopoverContentSize:CGSizeMake(pickerViewWidth, pickerViewHeight) animated:NO];

  [popover presentPopoverFromRect:anchor inView:self.webView.superview  permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];   

  return popover;
}

this line:

self.datePicker.date = [formatter dateFromString:dateString];

finally leads to crash, and with debug, i found the value of dateString is:

2014-10-17T10:0:00Z

2014-10-17T20:0:00Z

and it crash from second display, the first time is always ok

could you please give me some clue? thanks

michael

finally i find out the issue:

the source code of cordova DatePicker, reuse the UIDatePicker instance:

if(!self.datePicker){
    self.datePicker = [self createDatePicker];
    [self.datePicker addTarget];
}

and, it works fine in iOS7, but lead to crash in iOS8.

in iOS8, don't share UIDatePicker instance in multi UIView, so i modify the code to:

// in iOS8, UIDatePicker couldn't be shared in multi UIViews, it will cause crash. so   create new UIDatePicker instance every time
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {

    self.datePicker = [self createDatePicker:options frame:frame];
    [self.datePicker addTarget:self action:@selector(dateChangedAction:) forControlEvents:UIControlEventValueChanged];

}else{

    if(!self.datePicker){
        self.datePicker = [self createDatePicker:options frame:frame];
        [self.datePicker addTarget:self action:@selector(dateChangedAction:) forControlEvents:UIControlEventValueChanged];
    }
}

hope this can help someone like me

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Related Related

HotTag

Archive