Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect which segue identifier activated current view controller

I'm just looking for a way to detect which Segue Identifier activated the current viewController. I'm in need of doing this as I have conditions that might not be met, but can be referenced from another viewController, which then I'd like to highlight a few labels using that specific segue ID. Has anyone needed to do this before? How did you approach this?

like image 802
Nathan Denlinger Avatar asked Jul 19 '17 15:07

Nathan Denlinger


1 Answers

Probably you should create on your "current view controller" a property to store the name of the segue and then on the controller which uses the segue to instantiate your "current view controller" you assign it before fire the segue execution:

ObjectiveC:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString:@"YourSegueName"]) {

    // Get destination view
    CurrentVC *vc = [segue destinationViewController];

    // Get button tag number (or do whatever you need to do here, based on your object
    vc.segueName = @"YourSegueNam";
}}

Swift 3:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "YourSegueName"
    {
        if let destinationVC = segue.destination {
            destinationVC.segueName = segue.identifier
        }
    }
}

Is that what you need? Let me know. Anyway I still do not know why you want to do that.

like image 50
matiasdim Avatar answered Oct 13 '22 18:10

matiasdim