使用 UIPopoverController 时出错

发布于 2024-12-22 08:17:49 字数 1315 浏览 4 评论 0原文

在我当前的应用程序中,我试图在单击工具栏按钮时显示菜单屏幕。我发现最好的方法是使用 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)];

有什么想法吗?预先感谢

}

这是它产生的错误:

 *** 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)

In my current app, I am trying to make a menu screen apear when I click a tool bar button. I found that the best way to do this is to use a UIPopoverController to show a custom view that I have created. However, something about my current code is flawed. When I run my app and push the button, I get an error that says that it is reaching dealoc while the popover is still visible. Even after looking at several examples of similar problems, I can't for the life of me figure out how to fix this. Here is my code:

-(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)];

Any Ideas? Thanks in advance

}

This is the error that it produces:

 *** 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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

拥有 2024-12-29 08:17:49

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

@property (nonatomic, retain) UIPopoverController *myPopover;

在实现 .m 文件中:

//right after @implementation YourCurrentClassName
@synthesize myPopover;

在 -(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

Try this, in the header .h file of the current class:

@property (nonatomic, retain) UIPopoverController *myPopover;

And in the implementation .m file:

//right after @implementation YourCurrentClassName
@synthesize myPopover;

And in side the -(IBAction)newMenu:(id)sender method, replace the last two lines with these:

[taskPop setPopoverContentSize:CGSizeMake(400, 500)];
self.myPopover = taskPop;
[self.myPopover presentPopoverFromBarButtonItem:newTaskButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[taskPop release];  //if not using ARC
生生漫 2024-12-29 08:17:49
Here Popover is a popovercontroller

if (self.popover) {
         [self.popover dismissPopoverAnimated:YES];
}
Here Popover is a popovercontroller

if (self.popover) {
         [self.popover dismissPopoverAnimated:YES];
}
红衣飘飘貌似仙 2024-12-29 08:17:49

你在哪里释放了taskPop对象。

如果是在演示之后,那么这可能就是原因。

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

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

同样,根据 Apple 的说法,如果您以编程方式关闭控制器,则不会调用此委托方法。在这种情况下,当您以编程方式关闭 PopoverController 时,请释放它。

希望这有帮助。

Where have you released the taskPop object.

If it is right after the presentation, then that could be the reason.

Set the delegate and release the popoverController in the below delegate method:

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

Again, according to Apple, this delegate method is not called if you programmatically dismiss the controller. In such cases, release the PopoverController when you dismiss it programmatically.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文