IOS7 and iOS8 segue.destinationViewController

I am trying to make my application work with both iOS7 and iOS8, and I ran into a problem in my prepareForSegue methods in my controllers.

In iOS8, segue.destinationViewController has a UINavigationController class, so I use [[segue.desinationViewController viewControllers] objectAtIndex:0] , which works fine, but in iOS7 segue.desinationViewController has a CMAMyViewControllerClassName class, which will obviously throw an error message when I try to viewContollers .

I found this solution that will work, but I was wondering if there is a better solution? Apart from the last message, I could not find anything. If there is no β€œright” solution, I will create a method that gets the correct view controller; I'm just wondering how other people dealt with this situation.

Thanks!

+1
source share
1 answer

This issue is resolved by checking the destination view controller class before attempting to access one of its properties:

 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { DestController *vc = segue.destinationViewController; if ([dvc isKindOfClass:[DestController class]]) dvc.propertyName = @"Property Value"; else // do something else } 

Taken from the solution in this thread.

+1
source

All Articles