iphone - 使用 UIPopoverController 时出错

标签 iphone objective-c ios ios4 uipopovercontroller

在我当前的应用程序中,我试图在单击工具栏按钮时显示菜单屏幕。我发现最好的方法是使用 UIPopoverController 来显示我创建的自定义 View 。但是,我当前的代码存在一些缺陷。当我运行我的应用程序并按下按钮时,我收到一条错误消息,指出它正在到达 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)

最佳答案

试试这个,在当前类的头文件.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

关于iphone - 使用 UIPopoverController 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8609122/

相关文章:

ios - iOS app 的截图方法是什么?

jquery - 我正在构建的 Wordpress 页面正在使我的 iPhone 崩溃

iphone: -[CFString release]: 消息发送到已释放的实例

iphone - Objective-C:将分钟转换为时间

ios - 使用旧金山字体将 HTML 解析为 NSAttributedString? (iOS 9)

iphone - 从 UITableView 中删除部分

java - 无法使用 Obj-C 解密使用 Java 加密的 AES 数据

iphone - 导入 .m 实现文件时出错

ios - 为 .xib View 设置 ViewController

ios - Alamofire 回调永远不会返回