[英]how to enable the customview controller with view after dismiss Second viewcontroller in swift
我有两个视图控制器imag 1.第一个视图控制器是主要的,第二个是CustomAlertviw控制器主视图控制器就像上面的图像,当我点击继续显示customalertview控制器,就像图像一样。 当点击输入pin按钮时我必须关闭视图控制器并在主视图控制器上显示带有uiview的视图控制器但是尝试了,它显示了视图控制器,还有一个自定义视图没有显示它崩溃我的应用程序
主视图代码
@IBAction func backButtonClicked(_ sender: UIButton) {
let myAlert = UIStoryboard(name: "CustomAlertview", bundle: nil).instantiateViewController(withIdentifier: "CustomAlertViewController") as? CustomAlertViewController
myAlert?.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
myAlert?.modalTransitionStyle = UIModalTransitionStyle.crossDissolve
self.present(myAlert!, animated: true, completion: nil)
}
Customalertview controller
@IBAction func enterPinButtonClick(_ sender: Any) {
self.dismiss(animated: true, completion: nil)
let myAlert = UIStoryboard(name: "ScanAndPay", bundle: nil).instantiateViewController(withIdentifier: "ScanAndPayDetailsEntryViewController") as? ScanAndPayDetailsEntryViewController
myAlert?.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
myAlert?.modalTransitionStyle = UIModalTransitionStyle.crossDissolve
self.present(myAlert!, animated: true, completion: nil)
myAlert.valuespass()
}
inside main view controller one function calling from the customalrerview
func valuespass()
{
DispatchQueue.main.async {
self.authType = 1
self.authStatus = false
print("this is calling")
self.pinStatusLabel.text = "Please enter a 4-digit Security PIN"
}
当我从自定义警报视图应用程序调用此函数时崩溃并显示hread 1:致命错误:在解开Optional值时意外发现nil此错误。 如何在解除自定义视图控制器后显示所有信息。
你差不多完成了。 从FirstView
呈现ScanAndPay
而不是CustomAlertview
。
我已经完成了使用Delegate
因为我认为它适合这种情况。 按照以下步骤 -
第1步:
在FirstViewController中 ,
添加 - CustomAlertviewDelegate
这样的事情 -
class FirstViewController: UIViewController, CustomAlertviewDelegate {
现在替换你的backButtonClicked
方法 -
@IBAction func backButtonClicked(_ sender: UIButton) {
let myAlert = UIStoryboard(name: "CustomAlertview", bundle: nil).instantiateViewController(withIdentifier: "CustomAlertViewController") as? CustomAlertViewController
myAlert?.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
myAlert?.modalTransitionStyle = UIModalTransitionStyle.crossDissolve
myAlert.delegate = self
self.present(myAlert!, animated: true, completion: nil)
}
添加CustomAlertviewDelegate
的新Delegate
方法 -
func ScanAndPayView(){
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
let myAlert = UIStoryboard(name: "ScanAndPay", bundle: nil).instantiateViewController(withIdentifier: "ScanAndPayDetailsEntryViewController") as? ScanAndPayDetailsEntryViewController
myAlert?.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
myAlert?.modalTransitionStyle = UIModalTransitionStyle.crossDissolve
self.present(myAlert!, animated: true, completion: nil)
}
}
第2步:
现在是CustomAlertview的时间,
为类的顶级添加协议 -
protocol CustomAlertviewDelegate: class {
func ScanAndPayView()
}
class CustomAlertview: UIViewController{
weak var delegate : CustomAlertviewDelegate!
...
override func viewDidLoad() { // Rest of your code
}
现在是时候关闭当前视图控制器并通知FirstViewController
呈现ScanAndPay view Controller
-
@IBAction func enterPinButtonClick(_ sender: Any) {
delegate.ScanAndPayView()
self.dismiss(animated: true, completion: nil)
}
希望它能帮助你实现你想要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.