收到以下错误:
- 在弹出窗口仍然可见时到达[UIPopoverController dealloc]。
这是导致问题的代码:
-(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(非原子,强)UIPopoverController * popoverController;
我已标记导致坠机的线路;我将所有的PopoverControllers更改为实例变量,问题现在解决了,但现在已经把它变成了丑陋的头脑。我还能做些什么来阻止这种情况?
答案 0 :(得分:1)
检查popoverController在 showModalTime 方法中是否可见,因为popoverController覆盖
if ([popoverController isPopoverVisible]) {
[popoverController dismissPopoverAnimated:YES];
}
答案 1 :(得分:0)
你有没有合成这个属性?如果没有,您现在可能拥有popoverController
和_popoverController
变量......
尝试将对popoverController
的所有引用更改为self.popoverController
...
self.popoverController = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
self.popoverController.delegate = (id)self;
[self.popoverController setPopoverContentSize:CGSizeMake(200, 216) animated:NO];
答案 2 :(得分: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];
试试这个..
这可能对你有帮助.............