3

Is it impossible to present a popover controller from a view controller that's presented as UIModalPresentationFormsheet? or am I missing something?

This code works fine on a non-modal view controller, and displays the popover correctly.(WEPopoverController is a custom implementation from here.)

    GenericDataTableViewController *genericDataController = [[GenericDataTableViewController alloc] initWithNibName:@"GenericDataTableViewController" bundle:[NSBundle mainBundle]];

    genericDataController.dataSource = [NSMutableArray arrayWithObjects:@"asli", nil];
    genericDataController.delegate = self;
    genericDataController.contentSizeForViewInPopover = CGSizeMake(300, 46 * [genericDataController.dataSource count]);

    self.popoverController = [[[WEPopoverController alloc] initWithContentViewController:genericDataController] autorelease];
    self.popoverController.delegate = self;
    [self.popoverController presentPopoverFromRect:((UIButton *)sender).frame
                                            inView:self.view
                          permittedArrowDirections:UIPopoverArrowDirectionUp
                                          animated:YES];
    [genericDataController release];

But when I put this inside the modal view controller, this presents the popover below the modal controller, i.e. on the view controller that presents the modal one. So it cannot be seen by the user.

How can I solve this?

aslı
  • 8,740
  • 10
  • 59
  • 80
  • 1
    I created a trivial storyboard: the initial view has a button that does a modal segue to second VC. The second VC has a button that does a popover segue to a third VC. The popover appears correctly. So yes, it's possible. – rob mayoff Nov 29 '11 at 22:26
  • In your code, is `self` the modal VC, or is it the VC that presented the modal VC? – rob mayoff Nov 29 '11 at 22:27
  • self is the modal VC. I couldn't understand your first comment rob, what's a segue? – aslı Nov 30 '11 at 06:24
  • A segue is an object in a storyboard that defines a transition between view controllers. A storyboard is a new kind of XIB supported in iOS 5.0. I used a storyboard to test a popover on a modal VC because a storyboard let me do the test without writing any code. – rob mayoff Nov 30 '11 at 06:32
  • Yes, you're right the problem is due to the implementation of the WEPopoverController. It seemed to work so seemlessly that I never suspected it. A UIPopoverController can be presented from a modal view controller. Why don't you write your comment as an answer? It would be more readable to the others who will need this question later. And thanks :] – aslı Nov 30 '11 at 07:44
  • I didn't make it an answer because it didn't solve your problem. But you can upvote comments too... ;) – rob mayoff Nov 30 '11 at 07:45
  • OK then, the answer is don't use WEPopoverController :) – aslı Nov 30 '11 at 08:11

1 Answers1

3

The answer is explained in the comments of the question but I'm summarizing it here for a cleaner Q&A.

There aren't any restrictions about displaying a popover controller from inside a form sheet, if your popover controller is UIPopoverController. My problem was due to the implementation of WEPopoverController.

So, sacrifice the visual experience and continue with the good old UIPopoverController.

aslı
  • 8,740
  • 10
  • 59
  • 80
  • 1
    while adding button to `navigationController` and present it as popover using `uipopovercontroller` action executed only in first click. after dismissal n then presenting it action selector not getting executed. – Rafeek Nov 05 '13 at 06:20