1

Hi friends,

On clicking the toolbar button, my popover view appears. When i rotate the simulator to landscape orientation , following error message is displayed :

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)

Code to handle my button event is :

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

}

Thanks..

Ankur
  • 5,086
  • 19
  • 37
  • 62
Rocky
  • 1,427
  • 1
  • 28
  • 65
  • http://stackoverflow.com/questions/3377001/popovers-cannot-be-presented-from-a-view-which-does-not-have-a-window – Zaraki Aug 23 '12 at 09:08

1 Answers1

0

Here you need to add code to dismiss the popover from the view when you changing the orientation.

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

So, put your code in the method shouldAutorotateToInterfaceOrientation() when changing the orientation and it will work.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

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

return YES;

}

If you have any more questions then feel free to ask.

AppAspect
  • 4,461
  • 2
  • 30
  • 46
  • can u tell me why we have to dismiss this popover on orientation change yes it working but it not wrong way to do please explain me – Rocky Aug 23 '12 at 11:07
  • Here it is the default behavior of popover controller and as you have added via the BarButtonItem. So, when you rotate it changes the position. But here you can still make it working what you need. Just call the same function to add the popover after orientation changes to another mode from current orientation. So, first remove the popover and at the same time add again as per your orientation and I think that you want to have in the functionality. If again any problem then let me know, I will help you to solve this issue. – AppAspect Aug 23 '12 at 11:38
  • so how to keep refrence of popover view on landscape mode also it another way to do i call same function on orientation code but it not work please explain how it will work – Rocky Aug 24 '12 at 05:41
  • Here just after you change your orientation, you can call the function to show the popover. Now to track your orientation you can use one variable that store as landscape or portrait and based on that you can show your popover function and set the frame size, etc. – AppAspect Aug 24 '12 at 05:46