没有UI元素的Segue和Unwind segue

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

我一直在寻找答案,但没有成功。

我有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

帮助将不胜感激:)

swift segue unwind-segue
1个回答
1
投票

我仍然不明白segue是如何给你造成问题的,但如果你真的不想使用segues,你可以尝试以编程方式呈现和解雇VC。

这个想法是这样的:

  • 创建VC的实例
  • 通过设置一些属性将数据传递给它
  • 当下!
  • 在VC中,解雇。

如果将VC嵌入导航控制器,实际代码将有所不同。你可以在导航控制器上调用presentdismiss,而不是调用pushVCpopVC

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上查找更多信息。

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