我一直在寻找答案,但没有成功。
我有UIViewController
A和B.他们没有在Storyboard中链接,我想从A到B执行Segue
,点击B中的按钮,激活unwindSegue
到A.
到目前为止,我有:
1)A中的@IBAction
放松回到2)从A到B准备Segue的功能(在A中)3)从B到A调用unwindSegue
的按钮
我缺少的是2中函数的逻辑。
有关B的更多信息:
标题:FilterView类:FilterViewController故事板ID:FilterView
我尝试创建一个segue:
let segueToFilter = UIStoryboardSegue(identifier: "SegueToFilterView", source: self, destination: FilterViewController)
想到这可能只是让我得到我需要的东西。
但我得到这个错误:
Cannot convert value of type 'FilterViewController.Type' to expected argument type UIViewController
帮助将不胜感激:)
我仍然不明白segue是如何给你造成问题的,但如果你真的不想使用segues,你可以尝试以编程方式呈现和解雇VC。
这个想法是这样的:
如果将VC嵌入导航控制器,实际代码将有所不同。你可以在导航控制器上调用present
和dismiss
,而不是调用pushVC
和popVC
。
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "FilterView") as FilterViewController
vc.someProperty = someData // this is where you pass data
vc.present(vc, animated: true, completion: nil)
要传回数据,您应该通过创建第一个VC符合的FilterViewDelegate
来使用委托模式。在Google上查找更多信息。