2

I have a ViewController that when the right barButton is pressed, a popover view shows. The popover view is a table view controller,

The problem is that when the popover shows, it just shows a view (not a table view).

enter image description here But when the popover is dismissed, you can see that it flips to a tableview really quickly before it disappears.

enter image description here Why would this be?

Update: Added popController.sourceView = sender; at the end here per @sticker:

- (IBAction)pressedButton:(id)sender {
    NSLog(@"Pressed Button");

    // grab the view controller we want to show
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *controller = [storyboard instantiateViewControllerWithIdentifier:@"Pop"];

    // present the controller
    // on iPad, this will be a Popover
    // on iPhone, this will be an action sheet
    controller.modalPresentationStyle = UIModalPresentationPopover;
    [self presentViewController:controller animated:YES completion:nil];

    // configure the Popover presentation controller
    UIPopoverPresentationController *popController = [controller popoverPresentationController];
    popController.permittedArrowDirections = UIPopoverArrowDirectionAny;
    popController.barButtonItem = self.barbutton;
    popController.delegate = self;

    // Added per @sticker
    popController.sourceView = sender;
}

Also made sure PopTableViewController had <UITableViewDelegate, UITableViewDataSource> for sure.

I'm still getting no tableview showing until the popover gets dismissed:

enter image description here

(below is what happens as soon as popover is dismissed and animating away)

enter image description here

SRMR
  • 3,064
  • 6
  • 31
  • 59
  • 1
    you need set sourceView for popController and don't forget set datasource and delegate for your table view. – Trung Phan Jun 07 '16 at 03:40
  • @sticker Thanks for the response! So in my `ViewController` at the end of the `pressedButton:` I added `popController.sourceView = sender;`, then I went to the `PopTableViewController` and made sure it had ``. I'm getting the table view rows correct, but its not showing it in a table view still (until I dismiss the popover, then it still shows the table view for a quick second as it is being dismissed). Did I miss any part of your suggestion, or do you know what other piece I need? Thanks! – SRMR Jun 07 '16 at 14:37
  • @sticker you know what, unless you have any other ideas, maybe its just a bug in Simulator per http://stackoverflow.com/a/34108147/4205674 – SRMR Jun 07 '16 at 15:33
  • Otherwise, if you want to add you're comment as an answer then I can mark as solved – SRMR Jun 07 '16 at 15:33
  • Oh, i don't saw the row data like One, two, three so i thing your problem is setup wrong tableView. Glad to see it working fine. – Trung Phan Jun 07 '16 at 15:40

1 Answers1

1

I just try this one and it work fine Hope it help you

 self.tbVC.modalPresentationStyle = UIModalPresentationPopover;
    UIPopoverPresentationController *popOverVC =   [self.tbVC popoverPresentationController];
    popOverVC.barButtonItem = sender;
    popOverVC.permittedArrowDirections = UIPopoverArrowDirectionAny;


    [self presentViewController:_tbVC animated:YES completion:nil];
Trung Phan
  • 923
  • 10
  • 18