[英]How to dismiss formSheet Modal from ParentViewController?
I'm making a modal view that presents when the user touch up on a button. 我正在制作一个模态视图,当用户触摸按钮时显示。 At the moment, I already show the modal and I can use that modal interface.
目前,我已经显示了模态,并且可以使用该模态界面。
Now I wan't to dismiss the modal when a button inside the modal is pressed and after that do a segue from it's parent to another view. 现在,当我按下模态内部的按钮时,我将不关闭模态,然后从模态的父视图切换到另一个视图。
let summary = SummaryViewController(nibName: "SummaryViewController", bundle: nil)
summary.preferredContentSize = CGSize(width: 800, height: 300)
summary.modalPresentationStyle = UIModalPresentationStyle.formSheet
self.present(summary, animated: true, completion: nil)
SummaryViewController have the following code: SummaryViewController具有以下代码:
import UIKit
class SummaryViewController: UIViewController, UITextViewDelegate {
@IBOutlet weak var summaryTV: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
summaryTV.delegate = self
summaryTV.textColor = UIColor.lightGray
summaryTV.text = "Escriba el resumen de la visita"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func textViewDidBeginEditing(_ textView: UITextView) {
if textView.textColor == UIColor.lightGray {
textView.text = nil
textView.textColor = UIColor.black
}
}
func textViewDidEndEditing(_ textView: UITextView) {
if textView.text.isEmpty {
textView.textColor = UIColor.lightGray
textView.text = "Escriba el resumen de la visita"
}
}
@IBAction func saveSummary(_ sender: Any) {
print("SummaryTV: \(summaryTV.text)")
}
// MARK: Segues
// Overrided functions for segues. Ordered according to segue flow.
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
// If false, segue cancelled. Segue identifier is a parameter of the function.
// If you use function 'performSegue()' flow do not pass this function.
if !Reachability.isConnectedToNetwork() {
CommonAlerts.inetAlert(vc: self)
return false
}
return true
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
}
}
So when the user press the button inside the modal view, the IBAction saveSummary
is triggered. 因此,当用户按下模式视图内的按钮时,将触发IBAction
saveSummary
。 In that moment I want the parent view controller who present the modal to capture the text on the modal and dismiss the modal. 在那一刻,我希望呈现模式的父视图控制器捕获模式上的文本并关闭模式。 How can I do it?
我该怎么做?
@IBAction func saveSummary(_ sender: Any) {
print("SummaryTV: \(summaryTV.text)")
self.presentingViewController.dismissViewControllerAnimated(false,
completion: nil)
}
As for communication, you can setup a weak delegate to presenting VC which will implement a protocol: 对于通信,您可以设置一个弱代表来呈现VC,以实现协议:
protocol SummaryResult {
func saveResult(summary: String)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.