gpt4 book ai didi

ios - 如何从 ParentViewController 中关闭 formSheet Modal?

转载 作者:行者123 更新时间:2023-11-30 11:51:49 26 4
gpt4 key购买 nike

我正在制作一个模态视图,当用户触摸按钮时会显示该 View 。目前,我已经显示了模式,并且可以使用该模式界面。

现在我不想在按下模式内的按钮时关闭模式,然后从它的父 View 切换到另一个 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 有以下代码:

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?) {

}
}

因此,当用户按下模态视图内的按钮时,会触发 IBAction saveSummary。在那一刻,我希望呈现模式的父 View Controller 捕获模式上的文本并关闭模式。我该怎么做?

最佳答案

@IBAction func saveSummary(_ sender: Any) {
print("SummaryTV: \(summaryTV.text)")

self.presentingViewController.dismissViewControllerAnimated(false,
completion: nil)
}

对于通信,您可以设置一个弱委托(delegate)来呈现将实现协议(protocol)的 VC:

protocol SummaryResult {
func saveResult(summary: String)
}

关于ios - 如何从 ParentViewController 中关闭 formSheet Modal?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48266297/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com