Dismiss Popover After Touch

Dismiss Popover after touch

I have already answer same problem over here.

There scenario is different but solution is same

You have to write code for dismiss presented view controller on completion of current view controller.

Write below code on your dismissVIew method of LastViewController.swift

 var tmpController :UIViewController! = self.presentingViewController;

self.dismissViewControllerAnimated(false, completion: {()->Void in
println("done");
tmpController.dismissViewControllerAnimated(false, completion: nil);
});



Download link

How to dismiss a popover from parent in swift

Just call dismiss method using parent's presentedViewController property, like ....

self.presentedViewController.dismissViewControllerAnimated(true, completion: nil)

For Swift 3.0

self.presentedViewController?.dismiss(animated: true, completion: nil)

Swift: Popover dismiss callback

Protocols and delegations are solution to such problems. In my case I defined a protocol and conformed the MainViewController to the protocol.

//SecondViewController
protocol MyDelegate{
func DoSomething(text:String)
}

class SecondViewController: UIViewController {

var delegate:GetTextDelegate?

var inputTextDelegate:String = ""

override func viewDidLoad() {
newText.text = inputTextDelegate
}

@IBAction func dismissPopover(sender: UIButton) {
dismissViewControllerAnimated(true, completion: nil)
//This dismisses the popover but does not notify the MainViewConroller
}
@IBAction func doneButtonAction(sender: UIButton) {
if let delegate = self.delegate {
delegate.DoSomething(newText.text)
self.dismissViewControllerAnimated(true, completion: nil)
}
}
}

class MainViewController: UIViewController, UIPopoverPresentationControllerDelegate, MyDelegate {


override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{

if segue.identifier == "GoToSecondViewControllerSegue"
{
var vc = segue.destinationViewController as! SecondViewController
vc.delegate = self
vc.inputTextDelegate = "I'm a popover!"
}
}

func popoverPresentationControllerDidDismissPopover(popoverPresentationController: UIPopoverPresentationController) {
//...
}

func DoSomething(text: String) {
//Do whatever you want
println(text)
}

}

How to dismiss a view controller in a popover after touching a button that accepts a choice

Shouldn't you call something like:

   [popoverController dismissPopoverAnimated:YES];

to dismiss the popover? Or am I not understanding something?

Disable Dismiss Popover On Background Tap Swift

Set the delegate.

popover.popoverPresentationController?.delegate = self

Preventing Popover Dismissal When Tapping Outside (Swift)

In swift 3, ios 10

After implementing UIPopoverPresentationControllerDelegate the following function seems to do the trick.

func popoverPresentationControllerShouldDismissPopover(_ popoverPresentationController: UIPopoverPresentationController) -> Bool {
return false
}

I hope this helps if anyone is still looking for a solution.



Related Topics



Leave a reply



Submit