簡體   English   中英

使用UIPopoverController時出錯

[英]Error using UIPopoverController

在我當前的應用中,當我單擊工具欄按鈕時,我試圖使菜單屏幕出現。 我發現執行此操作的最佳方法是使用UIPopoverController顯示我創建的自定義視圖。 但是,關於我當前代碼的某些地方存在缺陷。 當我運行我的應用程序並按下按鈕時,我收到一條錯誤消息,指出它仍會顯示脫發,而彈出窗口仍然可見。 即使看了幾個類似問題的例子,我也無法畢生想出解決方法。 這是我的代碼:

-(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
Here Popover is a popovercontroller

if (self.popover) {
         [self.popover dismissPopoverAnimated:YES];
}

您在哪里發布了taskPop對象。

如果恰好在演講之后,那可能就是原因。

在下面的委托方法中設置委托並釋放popoverController:

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

同樣,根據Apple的說法,如果您以編程方式關閉控制器,則不會調用此委托方法。 在這種情況下,以編程方式將其關閉時,請釋放PopoverController。

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM