0

收到以下错误:

- [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 更改为实例变量,问题似乎已解决,但现在已经抬起了它的丑陋脑袋。我还能做些什么来防止这种情况发生?

4

3 回答 3

1

检查 popoverController 在showModalTime方法中是否可见, 因为 popoverController 覆盖

  if ([popoverController isPopoverVisible]) {
            [popoverController dismissPopoverAnimated:YES];
        }
于 2013-10-14T13:40:37.650 回答
0

你合成了属性吗?如果没有,你现在可能有一个popoverController和一个_popoverController变量......

尝试将所有引用更改popoverControllerself.popoverController...

self.popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
self.popoverController.delegate = (id)self;
[self.popoverController setPopoverContentSize:CGSizeMake(200, 216) animated:NO];
于 2013-10-14T13:23:38.977 回答
0

原因可能是这样的:PopoverController 找不到委托

解决方案:确保您已经在 viewController 的 .h 文件中声明了 popover 的委托,例如..

@interface FooController : UIViewController <UIPopoverControllerDelegate> {
    // ...
}
// ...
@end

然后在 .m 文件中实现委托方法,如..

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
    // do something now that it's been dismissed
}

更改代表的分配行,例如..

[popoverController setDelegate:self];

尝试这个..

这可能会帮助你......

于 2013-10-14T13:34:04.940 回答