ios - 关闭一个自定义弹出 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).
解决方案
您实际上并没有发布错误,但我想我知道问题所在。您可能正试图在旧的 VC 真正被解雇之前介绍下一个 VC。
您应该使用该方法的completion
参数dismiss
并将您的委托回调放在那里,以确保在完全解除之前您不会尝试做任何事情。
推荐阅读
- flutter - 当引用丢失时,垃圾收集器会关闭流控制器吗?
- python - 如何根据字典键和值过滤熊猫数据框行?
- react-native - 在 Web 项目上使用 React Navigation 时无法获取 /pageName
- database - PL/SQL 声明带有异常 [错误] 的游标
- python - 在文本中查找大写单词
- reactjs - React Js,Web Pack - 无法将 css 文件从 node_module 导入到反应组件中
- html - CSS,HTML - 通过按钮更改 HR 元素的颜色:活动
- java - 如何使用 ValidityAuditStrategy 批量插入审计表以进行收集
- javascript - 如何使用ckeditor制作所有textarea
- python - FTX API : 在不同的子账户上同时执行多个订单