How can I call an Objective-C method from another class?
For instance in xCode I have two scripts : the delegate and another one. How might I call someFunction on script2 from the delegate?
Thanks! Christian Stewart
How can I call an Objective-C method from another class?
For instance in xCode I have two scripts : the delegate and another one. How might I call someFunction on script2 from the delegate?
Thanks! Christian Stewart
If by "script" you mean class, you would need to link both classes.
if objectA is delegate of objectB, when objectB call a method from the delegate protocol:
if ([self.delegate resposndsToSelector:@selector(classBdidSomething:)]) {
[self.delegate performSelector:@selector(classBdidSomething:) withObject:self];
}
On the implementation of ClassA:
#pragma mark -
#pragma mark Delegate methods
- (void)classBdidSomething:(ClassB *)objectB {
[objectB methodToBeCalled];
}
If you get an error/warning (like warning: no '-methodToBeCalled' method found) when building on the line:
[objectB methodToBeCalled];
It means that you have to import ClassB to into your ClassA, by doing:
#import "ClassB.h"