Getting the following error:
-[UIPopoverController dealloc] reached while popover is still visible.
This is the code causing the problem:
-(void) showModalTime:(int)tag {
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView *popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 216)];
popoverView.backgroundColor = [UIColor redColor];
popoverContent.contentSizeForViewInPopover = CGSizeMake(200.0, 216.0);
// smaller for timePicker
timePicker=[[UIDatePicker alloc]init];
timePicker.frame = CGRectMake(0, 0, 200, 216);
timePicker.backgroundColor = UIColorFromRGB(0xeedd82);
timePicker.datePickerMode = UIDatePickerModeTime;
[timePicker setMinuteInterval:15];
[timePicker addTarget:self action:@selector(dateDidChange:) forControlEvents:UIControlEventValueChanged];
[popoverView addSubview:timePicker];
popoverContent.view = popoverView;
popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
popoverController.delegate = (id)self; // <-- this is the line that's causing the crash
[popoverController setPopoverContentSize:CGSizeMake(200, 216) animated:NO];
switch (tag) { // displays the popover datepicker
case 11: // store open time
[timePicker setTag:11];
[popoverController presentPopoverFromRect:tfShopOpens.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
break;
case 12: // store close time
[timePicker setTag:12];
[popoverController presentPopoverFromRect:tfShopCloses.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
break;
}
}
PopoverController is defined as an instance variable:
@property (nonatomic, strong) UIPopoverController *popoverController;
I have marked the line causing the crash; I changed all of my PopoverControllers to instance variables and the problem appeared solved, but now has reared it's ugly head. What else can I do to prevent this?
check popoverController is visible or not in showModalTime method because popoverController overwrite
if ([popoverController isPopoverVisible]) {
[popoverController dismissPopoverAnimated:YES];
}