Manually built:
[btnRun addTarget:self action:@selector(RunApp:) forControlEvents:UIControlEventTouchUpOutside];
Programmatically built: something of the following like ??
- (void) setRunButton:(UIButton*)objectName mySelector:(NSString*)funcName myControlEvent:(NSString*) controlEvent
{
[objectName addTarget:self action:@selector(funcName) forControlEvents:controlEvent];
}
I think you’d need something like the following:
It is unusual to pass a selector as an
NSStringbut you can useNSSelectorFromString()to convert the string name of the selector into a selector.Control events parameters are not strings they are an enumeration so I have changed the
myControlEventparameter to have theUIControlEventstype.It would be more usual to pass the selector to the method using
@selector(action). However,@selectoris handled at compile time so the parameter isn’t actually anNSString. In this case the method would look like: