收到以下错误:
- [UIPopoverController dealloc] 在 popover 仍然可见时达到。
这是导致问题的代码:
-(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 被定义为一个实例变量:
@property (nonatomic, strong) UIPopoverController *popoverController;
我已经标记了导致崩溃的行;我将我所有的 PopoverControllers 更改为实例变量,问题似乎已解决,但现在已经抬起了它的丑陋脑袋。我还能做些什么来防止这种情况发生?