I have this code in a prepareForSegue method
// Get destination view
UIViewController *viewController = [segue destinationViewController];
//See if it responds to a selector
if ([viewController respondsToSelector:@selector(setSomethingOrOther:)]) {
//if so call it with some data
[viewController setSomethingOrOther:something];
}
The code above means I do not have to include a reference to the actual class of the view controller being segue’d to. I can more loosely couple the two view controllers and just check if it responds to some property being set on it.
The problem is that when I do this I get the following compile time error:
No visible @interface for ‘UIViewController’ declares the selector ‘setSomethingOrOther:’
which is true of course. I know I could get around it by including a reference to the view but I would prefer to keep it separated. How can I work around this
Use the
performSelector:aSelectormethod, then you can call an undeclared selector.