我是在这里进行快速开发的新手,试图将iOS 13的演示样式更改为使用push样式。原始资源使用情节提要为视图控制器设置演示样式,但是其中一部分用
覆盖 override func prepare(for segue: UIStoryboardSegue, sender: Any?)
我设法通过pushViewController进行了转换,但是应用程序紧随其后崩溃了,请问这是什么问题? 这是全部功能
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let selectedIndex:Int? = menuTableView.indexPathForSelectedRow?.row
if (selectedIndex! == 0 || selectedIndex! == 1){
let submitViewController: SubmitViewController = segue.destination as! SubmitViewController
if (selectedIndex! == 0){
submitViewController.currency = Constant.CURRENCY_MYR
}else{
submitViewController.currency = Constant.CURRENCY_SGD
}
}else if (selectedIndex! == MENU_ACCOUNT_STATISTIC_INDEX){
let target: SearchResultViewController = segue.destination as! SearchResultViewController
target.toolbarOption = SearchResultViewToolBarOption.TOOLBAR_SMS
target.resultContent = self.resultContent
self.navigationController!.pushViewController(target, animated: true)
}
这是我得到的错误日志
2020-04-04 14:50:24.227072+0800 vboss[38120:1974490] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller <vboss.MenuViewController: 0x7fd906087e00>.'
答案 0 :(得分:0)
您可以尝试这样:
var selectedIndex : Int = -1
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.selectedIndex = indexPath.row
if (selectedIndex == 0 || selectedIndex == 1){
self.performSegue(withIdentifier: "submitViewController", sender: nil)
}else if (selectedIndex == MENU_ACCOUNT_STATISTIC_INDEX){
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let target = storyboard.instantiateViewController(withIdentifier: "searchResultViewController") as! SearchResultViewController
target.resultContent = self.resultContent
navigationController?.pushViewController(target, animated: true)
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let submitViewController: ViewController = segue.destination as! SubmitViewController{
if (selectedIndex == 0){
submitViewController.currency = Constant.CURRENCY_MYR
}else{
submitViewController.currency = Constant.CURRENCY_SGD
}
}
}
答案 1 :(得分:0)
问题已解决,这实际上是由于此部分使用的是故事板中为另一个ViewController设置的segue。因此,我要做的就是更改该特定剧情的情节提要板设置,并且这部分内容也可以解决。