将参数传递给选择器

时间:2014-03-20 23:14:26

标签: ios ios5 ios7

我有一个UIButton,它是UIView上的子视图。按下按钮时,我的应用程序应该将捕获的图像传递给@selector调用的函数。但是,我的研究表明,我无法使用UIButton的选择器向函数传递任何内容。我怎么能绕过这个?

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

1 个答案:

答案 0 :(得分:2)

您应该在handleButton按下方法中触发事件。你没有预设参数,buttonPress选择器传递一个参数,即发送事件的按钮。

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

- (void) handleButtonPress:(id)sender {
    UIImage * imageToFaceDetect = // get your image
    [self faceDetector:imageToFaceDetect];
}
相关问题