Question

I have two segues going out of my initial view controller. The push segue is connected to the cell and the modal is connected to the + UIBarButtonItem.

enter image description here

When this is what my prepareForSegue code looks like, everything is fine and filePath is sent through the push segue, but the filePath isn't passed through the modal segue.

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"showTimes"]) {
        [[segue destinationViewController] setFilePath:filePath];
    }

//    if ([[segue identifier] isEqualToString:@"addEvent"]) {
//        [[segue destinationViewController] setFilePath:filePath];
//    } 
}

If I uncomment the second if statement and segue identifier, the app crashes. filePath is sent nowhere. I've tried moving [[segue destinationViewController] setFilePath:filePath]; out of both if statements in an attempt to ensure that that line was executed, but that also crashes my app.

Both segues have the correct identifiers set up in the Attributes. However, I'm not sure that Xcode is actually realizing that the correct identifiers are set up because when I change the segue types, those changes aren't reflected the next time I run the app.

I'm a loss for what to do. I'm relatively new to Objective-C.

Was it helpful?

Solution

The addEvent segue points to a navigation controller, not your view controller. Instead, get your view controller and set the file path on that:

[[[segue destinationViewController] topViewController] setFilePath:filePath];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top