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
In Swift, Does Resetting the Property Inside Didset Trigger Another Didset
Alternate Approach to Inheritance for Swift Structs
With Firebase, Swift Removeobserver(Withhandle Does Not Remove the Observer
Swift - How to Create a View with a Shape Cropped in It
How Is a Type-Erased Generic Wrapper Implemented
Firebase Sign Out Not Working in Swift
Nstextalignment.Justified for Uilabel Does Not Work
How to Determine If a Variable Passed in Is Reference Type or Value Type
iOS 11 Uirefreshcontrol with Navigationbar Largetitle and Searchcontroller Disappearing
Clearing Uiwebview's Cache in Swift
Swift - Get Nsbundle for Test Target
How to Code Initwithcoder in Swift
Is There Any Way of Locking an Object in Swift Like in C#
App Crash on Sign in (Xcode 9.3) Exc_Bad_Access (Code=1, Address=0X1)
Swift 3:Fatal Error: Double Value Cannot Be Converted to Int Because It Is Either Infinite or Nan
Swiftui Onhover Doesn't Register Mouse Leaving the Element If Mouse Moves Too Fast