关闭一个自定义弹出窗口UIViewController并立即显示另一个自定义弹出窗口UIViewController -SWIFT

问题描述 投票:-1回答:2

我有一个主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).
ios swift delegates
2个回答
1
投票

你实际上没有发布错误,但我想我知道问题是什么。你可能试图在旧的实际上被解雇之前提出下一个VC。

你应该使用completion方法的dismiss参数并将你的委托回调放在那里,以确保你没有尝试做任何事情,直到它完全被解雇。


0
投票

createTagVC的演示文稿移动到runloop的下一个循环。这应该保证UI处于正确的“非呈现”状态。

DispatchQueue.main.async {
    present(createTagVC, animated: true, completion: nil)
}

有时候,在runloop结束之前,有些事情并没有真正完成。最好在下一个开始新鲜。

© www.soinside.com 2019 - 2024. All rights reserved.