我有两个UIViewController:A,B
假设有两个序列连接它们: C,D
一旦激活了segue,并且我在视图B中,我能知道是哪个段把我带到这里的吗?C还是D?
发布于 2018-09-01 01:27:12
有一个prepare(for: segue)函数,允许您在新的ViewController中设置属性。
class OriginViewController : UIViewController {
...
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if let destination = segue.destination as? SegueProtocol {
destination.transitionSegue = segue.identifier
}
}
}
class DestinationViewController : UIViewController, SegueProtocol {
var transitionSegue: String = ""
override func viewDidLoad() {
print("Segue: ", transitionSegue)
}
}
protocol SegueProtocol {
var transitionSegue : String { get set }
}编辑:根据评论建议,最好是一个符合协议的目的地,而不是一个特定类型的目的地。
发布于 2018-09-01 01:28:40
我不知道这方面的任何内置机制,但您可以让所有的目标视图控制器符合一个协议SourceSegueProtocol,该协议具有一个包含调用段的变量。
然后,在源代码视图控制器的prepare(for:sender:)方法中,您可以为符合SourceSegueProtocol的目标视图控制器设置该变量。
https://stackoverflow.com/questions/52120142
复制相似问题