Question

I have an UIButton that is subview on an UIView. When the button is pressed, my app is supposed to pass a captured image into a function called by the @selector. However, my research shows me that I am not able to pass anything to the function with the selector of the UIButton. How can I go around this?

[hangButton addTarget:self
               action:@selector(faceDetector: the image I want to pass in)
     forControlEvents:UIControlEventTouchUpInside];
Was it helpful?

Solution

You should trigger your events within a handleButton press method. You don't preset arguments, buttonPress selectors pass one argument, the button that is sending the event.

[hangButton addTarget:self
               action:@selector(handleButtonPress:)
     forControlEvents:UIControlEventTouchUpInside];

- (void) handleButtonPress:(id)sender {
    UIImage * imageToFaceDetect = // get your image
    [self faceDetector:imageToFaceDetect];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top