使用UIPopoverController时出错 [英] Error using UIPopoverController

查看:143
本文介绍了使用UIPopoverController时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

任何想法?提前致谢

}

这是它产生的错误:

 *** 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文件中:

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

@property (nonatomic, retain) UIPopoverController *myPopover;

在实现.m文件中:

//right after @implementation YourCurrentClassName
@synthesize myPopover;

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

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

这篇关于使用UIPopoverController时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆