I’m fairly sure this is a simple issue but it’s something that I’ve been unable to solve.
I am using the respondsToSelector method in an if statement to check whether a delegate implements a method. Inside the if statement I then call this selector. Nothing complex. But I get a warning saying the method is not found, (Screenshot). If however I include the header file for the class that implements the method, the warning goes away.
I suspect it could be to do with the order the sources are compiled perhaps?
Any help much appreciated.
Although you can create arbitrary selectors using
@selector(somethingHere:), you cannot call arbitrary methods on anidvariable without a compiler warning. The compiler will still check that the method/selector you are calling has been defined somewhere on a class or category.You need to include the appropriate header so the compiler knows that there are objects/classes in the system that can respond to that method, otherwise you could mistype a selector and never know about it.
edit:
OK I see now that you are implementing a delegate. In that case you need to declare a protocol with the appropriate methods, and use the type
id<ProtocolName>for your delegate. Then your class should be declared as implementing that protocol.