首页 > 解决方案 > 关闭一个自定义弹出 UIViewController 并立即呈现另一个自定义弹出 UIViewController -SWIFT

问题描述

我有一个带有主 UIViewController 的应用程序。当我按下按钮(“保存”)时,我会出现一个自定义弹出窗口(UIViewController)。在这个弹出窗口中,我有另一个按钮,如果我按下它,我想关闭当前的弹出视图控制器,然后立即呈现另一个不同的自定义弹出视图控制器。我可以关闭第一个弹出窗口,但随后出现错误(见下文)。我正在使用协议来使其正常工作,但我在某处犯了错误。请问有人可以建议吗?

[![在此处输入图像描述][1]][1]

class mainViewController: UIViewController, popUpDismissedDelegate{

  // CUSTOM PROTOCOL DELEGATE FUNCTION
  func popUpDimissed() {

    // SHOW ANOTHER POPUP TO CREATE CUSTOM HASHTAGS!
    let createTagVC = storyboard?.instantiateViewController(withIdentifier: "createTag") as! CreateHashTagPopUpViewController
    present(createTagVC, animated: true, completion: nil)
 }


 // SAVE PDF
 @IBAction func savePdf(_ sender: Any) {

    // SHOW CUSTOM SELECTION OH HASHTAGS TO ASSIGN PDF
    let popUpVC = storyboard?.instantiateViewController(withIdentifier: "hashtagpicker") as! CustomHashTagPopup
    popUpVC.delegate = self
    present(popUpVC, animated: true, completion: nil)
 }

}



protocol popUpDismissedDelegate {
   func popUpDimissed()
}

class CustomHashTagPopup: UIViewController, UITableViewDelegate, UITableViewDataSource{

  var delegate: popUpDismissedDelegate!

 // TAP ON CELLS
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

    if(indexPath == [0,0]){
        // OPTION TO CREATE A NEW HASHTAG
        self.dismiss(animated: true) {
            self.delegate.popUpDimissed()
        }

    }else{
        // DO NOTHING
        // TO SELECT A HASH TAG USE NEEDS TO PRESS ON THE CHECKBOX!
    }
}

}

错误:

 Warning once only: Detected a case where constraints ambiguously 
 suggest a height of zero for a tableview cell's content view. We're 
 considering the collapse unintentional and using standard height 
 instead.
 popup - viewDidDisappear
 Could not cast value of type 'UIViewController' (0x10c1ec1f0) to 
 'zapdocuments.CreateHashTagPopUpViewController' (0x107cd0520).
 2018-08-28 18:18:48.196815+0100 zapdocuments[28989:4660894] Could not 
 cast value of type 'UIViewController' (0x10c1ec1f0) to 
 'zapdocuments.CreateHashTagPopUpViewController' (0x107cd0520).

标签: iosswiftdelegates

解决方案


您实际上并没有发布错误,但我想我知道问题所在。您可能正试图在旧的 VC 真正被解雇之前介绍下一个 VC。

您应该使用该方法的completion参数dismiss并将您的委托回调放在那里,以确保在完全解除之前您不会尝试做任何事情。


推荐阅读