Here is an easy way to add some goals. Obviously, you want to create some error checking and make it more flexible, but hopefully you get the idea:
Write a method that allows other objects to add themselves as a target:
- (void) addTarget:(NSObject *)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents { if (controlEvents == UIControlEventValueChanged) { NSArray *targetAndAction = @[target, [NSValue valueWithPointer:action]]; [valueChangedArray addObject:targetAndAction];
You do not need to use UIControlEvents if you do not want this, and you do not need to use NSArrays to store all the material. The important thing is that you hover over the target and save the selector as an NSValue object.
When something happens, do an object selector:
- (void) somethingHappened {
Note that you may get a memory leak if the selector saves any objects (Xcode will warn you about this). Until your selectors return the objects they created / copied, you should be fine. A more detailed discussion of potential leakage potential leakage is available here: performSelector may cause leakage because its selector is unknown .
source share