Popover控制器无法正确显示视图

时间:2016-06-06 21:28:06

标签: ios objective-c uitableview uipopovercontroller

我有一个ViewController,当按下右barButton时,会显示一个弹出视图。弹出窗口视图是一个表视图控制器,

问题是当弹出窗口显示时,它只显示一个视图(不是表视图)。

enter image description here 但是当弹出窗口被解雇时,你可以看到它在它消失之前很快就会翻到桌面视图。

enter image description here 为什么会这样?

更新:根据@sticker在此处添加popController.sourceView = sender;

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

还确保PopTableViewController肯定有<UITableViewDelegate, UITableViewDataSource>

在弹出窗口被解雇之前,我仍然没有看到桌面视图:

enter image description here

(下面是弹出窗口被解除并动画播放后会发生的事情)

enter image description here

1 个答案:

答案 0 :(得分:1)

我只是尝试这个,它工作正常 希望它对你有所帮助

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


    [self presentViewController:_tbVC animated:YES completion:nil];