cdrguru
cdrguru

Reputation: 13

performSegueWithIdentifier failing presentPopoverFromBarButtonItem Popovers cannot be presented from a view which does not have a window

I have a Master/Detail view which opens a popover view via storyboard segue. There is an add button on the navigation bar of the Master view controller which works fine.

I added an editing mode where the same popover is invoked by selecting a table cell in edit mode. It fails from the [self performSegueWithIdentifier:@"addQuery" sender:self]; statement. The viewDidLoad in the popover is invoked, but after that the exception is thrown.

I am not invoking presentPopoverFromBarButtonItem - it seems to be coming from the performSegueWithIdentifier.

There is no question that the Master View Controller has a window - a table cell for that view was clicked to start the whole process that is failing.

The popover is the beginning of a navigation controller sequence, which may be part of the problem. Everything is working fine when it really is invoked by the button, just trying to programmatically invoke it is failing.

I have tried changing the "sender" for the performSegueWithIdentifier to no avail.

I suspect the problem has to do with the segue not being invoked by a button, and I do not know how to fake that out.

Any ideas?

Upvotes: 1

Views: 1134

Answers (2)

justas wza
justas wza

Reputation: 41

I have a similar issue:

I am using UIDocumentInteractionController to open a kaynote document in Kaynote app. I was using same code:

[docController presentOpenInMenuFromBarButtonItem:_actionBarButtonItem animated:YES];

Code above was opening popover from actiobBarButtonItem with options what app I would like to use to open my file. If I same thing from DetailViewController I get same error message as author of this thread: "Popovers cannot be presented from a view which does not have a window"

And I was able to find a quick solution for my issue . I am not sure if it will be relevant to yours. Instead of using "presentOpenInMenuFromBarButtonItem" I used "presentOpenInMenuFromRect" and thats it. You just need to define right place for popover to apear

Upvotes: 0

Mahesh
Mahesh

Reputation: 118

There appear to be some bugs in how ipad popover segue's work - see Wayne Hartman's blog post

A simple test revealed that viewWillAppear is being called after viewDidLoad.

I think I understand the problem... havent' worked out the solution yet.

The order in which the methods were called are...

  1. [initiate segue]
  2. viewDidLoad
  3. prepareForSegue
  4. viewWillAppear

I moved my initialization code to the viewWillAppear method - and it worked.

In general, I feel it may be a good idea to initialize within viewWillAppear instead of viewDidLoad anyway.

Upvotes: 1

Related Questions