0

I developed iPad application. There is a table view in screen. If user clicking to any cell then I opening the popover. I encounter an error like this is very rare

Fatal Exception NSInvalidArgumentException
-[UIPopoverController _commonPresentPopoverFromRect:inView:permittedArrowDirections:animated:]: Popovers cannot be presented from a view which does not have a window. 

Using the following method;

UIViewController *contentViewController = [[UIViewController alloc] init];
[contentViewController.view setFrame:CGRectMake(0, 0, 320, 460)];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:contentViewController] autorelease];

self.popOver=[[UIPopoverController alloc] initWithContentViewController:navController];
self.popOver.delegate = self;

CGRect rectInTableView = [self.menuItems rectForRowAtIndexPath:tableRowID];
CGRect rectInSuperview = [self.menuItems convertRect:rectInTableView toView:self.view];
rectInSuperview.size.width=320;

[self.popOver presentPopoverFromRect:rectInSuperview inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
[contentViewController release];
hiwordls
  • 781
  • 7
  • 17
  • 35
  • `if (self.view.window != nil) { [self.popOver presentPopoverFromRect:rectInSuperview inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES]; }` – user2545330 Sep 24 '13 at 07:22

4 Answers4

1

This means self.view is not on screen. Try tracing self to see which view controller you are referring to.

Odrakir
  • 4,254
  • 1
  • 20
  • 52
0

It gives error Because of your view is not on screen

You can try like this,

 CGRect rect = [tableView convertRect:[tableView rectForRowAtIndexPath: tableRowID]
                                      toView:tableView];

  [self.popOver presentPopoverFromRect:rect
                                           inView:tableView
                         permittedArrowDirections:UIPopoverArrowDirectionLeft
                                         animated:YES];
Toseef Khilji
  • 17,192
  • 12
  • 80
  • 121
0

try this it will help you. just findout the selected cell from tableView.

UITableViewCell * cell = [tab cellForRowAtIndexPath:tableRowID];

[self.popOver presentPopoverFromRect:cell.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
[contentViewController release];
0

Have you ever made this work? The UINavigationController is a subclass of a UIViewController but it is not a ContentViewController (UIViewController or UITableViewController) as documented by Apple in they View Controller Programming guide.

Anyway I was receiving the same message a few weeks ago which I reported to Apple as a bug. In my case if I go up the view hierarchy using a Navigation Controller, once I pop to root and open a Pop up (from the root view) it reports that self.View does not have any window. My work around solution was to change the code to use an existing NavigationBar as the anchor view instead of self.view. Code is as follows:

[popover presentPopoverFromRect:CGRectMake(0, 0, 1,self.navigationController.navigationBar.bounds.size.height) inView:self.navigationController.navigationBar permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];  
Ravi Gautam
  • 960
  • 2
  • 9
  • 20
Paulo
  • 1,245
  • 10
  • 8
  • The same code works for IOS 6.1 but does not work with the IOS 7 SDK. The same code works so long as you do not go up the navigation hierarchy and poptoroot. With my code I have tried to use different objects UIButtons as anchor with the same results – Paulo Sep 24 '13 at 08:09
  • You may also check this link - seems similar to what you are getting http://stackoverflow.com/questions/3377001/popovers-cannot-be-presented-from-a-view-which-does-not-have-a-window?rq=1 – Paulo Sep 24 '13 at 08:24