2016-06-06 28 views
1

我有一個ViewController,當按下右側barButton時,顯示彈出視圖。 popover視圖是一個表視圖控制器,Popover控制器不能正確顯示視圖

問題是當popover顯示時,它只顯示一個視圖(不是表視圖)。

enter image description here 但是當popover被解散時,你可以看到它在真正快速消失之前快速翻轉到tableview。

enter image description here 這是爲什麼?

更新:在末尾添加popController.sourceView = sender;這裏每@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; 
} 

還確保PopTableViewController<UITableViewDelegate, UITableViewDataSource>肯定。

我還沒有得到任何的tableview顯示,直到酥料餅被駁回:

enter image description here

(下面是酥料餅被解僱,離開動畫什麼,一旦發生)

enter image description here

+1

您需要爲popController設置sourceView,並且不要忘記爲您的表視圖設置數據源和委託。 – Nick

+0

@sticker感謝您的迴應!所以在'pressed的按鈕'的末尾的'ViewController'中:'我添加了'popController.sourceView = sender;',然後我去了'PopTableViewController'並確保它有''。我得到的表視圖行是正確的,但它沒有顯示在表視圖仍然(直到我解僱了彈出窗口,然後它仍然顯示錶視圖快速秒,因爲它被解僱)。我錯過了你的建議的任何部分,或者你知道我需要的其他部分嗎?謝謝! – SRMR

+0

@sticker你知道什麼,除非你有任何其他的想法,也許它只是一個模擬器中的bug每個http://stackoverflow.com/a/34108147/4205674 – SRMR

回答

1

我只是嘗試這一個,它工作正常 希望它可以幫助你

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


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

感謝您的幫助! – SRMR