使用UIPopoverController时出错

Rob*_*Rob 0 iphone objective-c uipopovercontroller ios4 ios

在我当前的应用程序中,当我单击工具栏按钮时,我正在尝试创建一个菜单屏幕apear.我发现最好的方法是使用UIPopoverController来显示我创建的自定义视图.但是,关于我当前代码的一些内容存在缺陷.当我运行我的应用程序并按下按钮时,我收到一条错误消息,表示当弹出窗口仍然可见时它正在达到dealoc.即使看了几个类似问题的例子,我也不能为我的生活弄清楚如何解决这个问题.这是我的代码:

-(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)];
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?提前致谢

}

这是它产生的错误:

 *** 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)
Run Code Online (Sandbox Code Playgroud)

use*_*234 12

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

@property (nonatomic, retain) UIPopoverController *myPopover;
Run Code Online (Sandbox Code Playgroud)

并在实现.m文件中:

//right after @implementation YourCurrentClassName
@synthesize myPopover;
Run Code Online (Sandbox Code Playgroud)

在 - (IBAction)newMenu:(id)sender方法的一边,用这些替换最后两行:

[taskPop setPopoverContentSize:CGSizeMake(400, 500)];
self.myPopover = taskPop;
[self.myPopover presentPopoverFromBarButtonItem:newTaskButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[taskPop release];  //if not using ARC
Run Code Online (Sandbox Code Playgroud)