使用UIPopoverController时出错

在我目前的应用程序中,当我点击一个工具栏button时,我正在尝试创build一个菜单屏幕apear。 我发现最好的方法是使用UIPopoverController来显示我创build的自定义视图。 但是,有关我目前的代码是有缺陷的。 当我运行我的应用程序,并按下button,我得到一个错误,说它是达到dealoc,而popup仍然可见。 即使看了几个类似问题的例子,我也无法想象如何解决这个问题。 这是我的代码:

-(IBAction)newMenu:(id)sender{ newTaskWindow *newTaskWin = [[newTaskWindow alloc]init]; UIView *test = [[UIView alloc]init]; test = newTaskWin.view; UIPopoverController *taskPop = [[UIPopoverController alloc]initWithContentViewController:newTaskWin]; [taskPop setDelegate:self]; [taskPop presentPopoverFromBarButtonItem:newTaskButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; [taskPop setPopoverContentSize:CGSizeMake(400, 500)]; 

有任何想法吗? 提前致谢

}

这是它产生的错误:

  *** Terminating app due to uncaught exception 'NSGenericException', reason: '- [UIPopoverController dealloc] reached while popover is still visible.' *** First throw call stack: (0x381fb8bf 0x37d471e5 0x381fb7b9 0x381fb7db 0x32065f71 0x37d430c5 0x37d44db7 0x2ecf 0x38155435 0x31cbe9eb 0x31d843cf 0x38155435 0x31cbe9eb 0x31cbe9a7 0x31cbe985 0x31cbe6f5 0x31cbf02d 0x31cbd50f 0x31cbcf01 0x31ca34ed 0x31ca2d2d 0x37f29df3 0x381cf553 0x381cf4f5 0x381ce343 0x381514dd 0x381513a5 0x37f28fcd 0x31cd1743 0x2bd5 0x2b6c) terminate called throwing an exception(gdb) 

试试这个,在当前类的头文件.h文件中:

 @property (nonatomic, retain) UIPopoverController *myPopover; 

并在执行.m文件中:

 //right after @implementation YourCurrentClassName @synthesize myPopover; 

并且在 – (IBAction)newMenu:(id)发送者方法中,用这些replace最后两行:

 [taskPop setPopoverContentSize:CGSizeMake(400, 500)]; self.myPopover = taskPop; [self.myPopover presentPopoverFromBarButtonItem:newTaskButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; [taskPop release]; //if not using ARC 
 Here Popover is a popovercontroller if (self.popover) { [self.popover dismissPopoverAnimated:YES]; } 

你在哪里发布了taskPop对象。

如果在演讲之后是正确的,那么这可能是原因。

设置委托并在下面的委托方法中释放popoverController:

 - (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController { 

同样,根据苹果公司的说法,如果以编程方式closures控制器,则不会调用此代理方法。 在这种情况下,当您以编程方式closuresPopoverController时,请释放它。

希望这可以帮助。