簡體   English   中英

如何在其內部點擊時關閉UIPopoverPresentationController。 (iOS,Swift)

[英]How to dismiss UIPopoverPresentationController on tap inside it. (iOS, Swift)

我已經成功實現了一個popviewcontroller,其中包含4個單元的表格視圖。 我想在選擇單元格時關閉popViewController,但是我似乎無法做到這一點。 在我的tableViewController中,我在didSelectRowAtIndexPath內部有一個方法,該方法將該MasterViewController的方法稱為“ updateToSelectedTab”。 我可以在此處打印出所選單元格的索引路徑,但是當選中該單元格時,我無法刪除popViewController。 我該怎么做呢?

在此處輸入圖片說明

//這是我們的MasterViewController類

@IBAction func pop(sender: AnyObject) {

    let contentView = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("popViewController") as! PopViewController
    contentView.modalPresentationStyle = UIModalPresentationStyle.Popover
    contentView.preferredContentSize = CGSizeMake(aButton.frame.width, 240.0)

    let popoverMenuViewController = contentView.popoverPresentationController!
    popoverMenuViewController.delegate = self
    popoverMenuViewController.permittedArrowDirections = UIPopoverArrowDirection.Any
    popoverMenuViewController.sourceView = view
    popoverMenuViewController.permittedArrowDirections = UIPopoverArrowDirection(rawValue:0)

    popoverMenuViewController.sourceRect = CGRectMake(aButton.frame.origin.x, aButton.frame.origin.y - 60, aButton.frame.width, aButton.frame.height)
    presentViewController(contentView, animated: true, completion: nil)
}

func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
    return UIModalPresentationStyle.None
}

//This method is called from didSelectRowAtIndexPath of the View Controller that handles the UIPopoverPresentationController
func updateToSelectedTab(tab: Int){
    print("Current tab \(tab)")
    //Need to dismiss controller here

}

我要做的就是在索引路徑委托方法的選擇行中添加以下代碼:

dismissViewControllerAnimated(true, completion: nil)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM