1

よう皆、

ツールバーボタンをクリックすると、ポップオーバービューが表示されます。シミュレータを横向きに回転させると、次のエラーメッセージが表示されます。

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPopoverController presentPopoverFromRect:inView:permittedArrowDirections:animated:]: Popovers cannot be presented from a view which does not have a window.'

*** First throw call stack:
(0x1b69052 0x1868d0a 0x1b11a78 0x1b119e9 0x9ae72e 0x9affcb 0x9b26eb 0x281a39 0x1b34885 0x1b347a8 0x1c61aa 0x5490d8 0x54d499 0x54d584 0x11ede00 0x15ff4f0 0x1aa0833 0x1a9fdb4 0x1a9fccb 0x209a879 0x209a93e 0x51ca9b 0x29dd 0x2955)

ボタンイベントを処理するコードは次のとおりです。

-(IBAction)name:(id)sender
{
    if ([_popover isPopoverVisible]) 
    {
        [_popover dismissPopoverAnimated:YES];
    }

    else {
        task * content = [[task  alloc] init];

        content.navigationItem.title =@"name"; 
        [content setDelegate:self];
        navController = [[UINavigationController alloc] initWithRootViewController: content]; 
        _popover = [[UIPopoverController alloc] 
                    initWithContentViewController:navController];
        _popover. popoverContentSize=CGSizeMake(350, 480);

        [_popover presentPopoverFromBarButtonItem:sender
                        permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    }

}

ありがとう..

4

1 に答える 1

0

ここでは、向きを変更するときにビューからポップオーバーを閉じるコードを追加する必要があります。

if ([_popover isPopoverVisible]) { [_popover dismissPopoverAnimated:YES]; }

したがって、方向を変更するときにコードをメソッドshouldAutorotateToInterfaceOrientation()に入れると、機能します。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

if ([_popover isPopoverVisible]) 
{
    [_popover dismissPopoverAnimated:YES];
}

return YES;

}

他にご不明な点がございましたら、お気軽にお問い合わせください。

于 2012-08-23T10:31:35.647 に答える