問題描述
查找正在使用的 segue (Finding the segue being used)
I am using a detail view controller which is linked from various segue. I would like to perform an action in viewDidLoad
depending on which controller is pushing the detail controller.
Is there a way I can figure out which segue is loading the detail controller?
‑‑‑‑‑
參考解法
方法 1:
You can use NSStringFromClass if you set a delegate for the detail VC. An alternate way would be to set the ID in a prepareForSegue:
method and either pass that to the detail VC or call a getter on the delegate.
NSString *class = [NSStringFromClass([self.delegate class]);
‑‑
‑ (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"scrollerSegue"])
{
ScrollViewController * target = segue.destinationViewController;
target.VC_Which_Pushed_ME = self.ID;
// and/or
target.delegate = self;
}
}
(by dadiduekappa、spring)