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:aSelector
method, then you can call an undeclared selector.
[viewController performSelector:@selector(setSomethingOrOther:)
withObject:something];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With