Ios Swift警报操作处理程序在特定情况下不工作
我正在创建一个显示用户评论的应用程序。用户输入注释,然后单击提交按钮,然后将出现警报操作视图。当单击警报视图中的“确定”按钮时,我试图将用户引导到我的第四视图控制器。这是我的代码,应该可以正常工作Ios Swift警报操作处理程序在特定情况下不工作,ios,swift,alert,handler,Ios,Swift,Alert,Handler,我正在创建一个显示用户评论的应用程序。用户输入注释,然后单击提交按钮,然后将出现警报操作视图。当单击警报视图中的“确定”按钮时,我试图将用户引导到我的第四视图控制器。这是我的代码,应该可以正常工作 let alert = UIAlertController(title: "Succesful", message: "Successfully added!", preferredStyle: .alert) alert.addAction(UIAlertAction(title: "OK", st
let alert = UIAlertController(title: "Succesful", message: "Successfully added!", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { _ in
let uivc = self.storyboard!.instantiateViewController(withIdentifier: "ViewController")
self.navigationController!.pushViewController(uivc, animated: true)
}))
self.present(alert, animated: true)
然而,当我点击OK按钮时,我得到了这个错误
“InvalidPathValidation”,原因:“(子项:)必须是非空字符串,且不包含“.”#“$”[”或“]”
FourthViewController是根据用户在过去三个ViewController上的选择创建的。基于在以前的视图控制器中单击的tableview单元格的组合,有一个唯一的fourthviewcontroller。我相信问题的出现是因为当我将用户引导到FourthViewController时,应用程序不知道FourthViewController包含什么,因为之前没有单击过tableview单元格。当我将VC的方向从FourthViewController更改为FirstViewController时,一切都运行得非常好
有可能解决这个问题吗?我将感谢任何帮助!非常感谢你,祝你今天愉快 如果我理解正确,第四个ViewController有一些变量,这些变量依赖于以前的ViewController。在这种情况下,只需初始化这些变量,设置它们的值:uivc.varName=value
您还可以执行一个序列,而不是实例化视图控制器,并且可以在“准备”功能中设置nextViewController的值。删除以下行表单操作完成
let uivc = self.storyboard!.instantiateViewController(withIdentifier:"ViewController")
self.navigationController!.pushViewController(uivc, animated: true)
self.navigate()
并生成一个函数,如下所示
func navigate(){
let uivc = self.storyboard!.instantiateViewController(withIdentifier:"ViewController")
self.navigationController!.pushViewController(uivc, animated: true)
}
现在添加以下操作完成
let uivc = self.storyboard!.instantiateViewController(withIdentifier:"ViewController")
self.navigationController!.pushViewController(uivc, animated: true)
self.navigate()
如下
let alert = UIAlertController(title: "Succesful", message: "Successfully added!", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { _ in
self.navigate()
}))
self.present(alert, animated: true)
你能更好地解释你的问题吗?不清楚你在问什么。现在试着解释得更清楚些。希望这有帮助@Bobbydickson这意味着你的代码中存在问题,而不是在上面发布的代码中,而是在其他任何地方,我相信这不是你发布的有问题的代码,试着找出问题所在,并在你遇到问题的地方发布准确的代码