Ios 将参数传递给选择器
我有一个UIButton,它是UIView上的子视图。当按下按钮时,我的应用程序应该将捕获的图像传递到@selector调用的函数中。然而,我的研究表明,我无法通过UIButton的选择器向函数传递任何信息。我怎么能绕过这个Ios 将参数传递给选择器,ios,ios5,ios7,Ios,Ios5,Ios7,我有一个UIButton,它是UIView上的子视图。当按下按钮时,我的应用程序应该将捕获的图像传递到@selector调用的函数中。然而,我的研究表明,我无法通过UIButton的选择器向函数传递任何信息。我怎么能绕过这个 [hangButton addTarget:self action:@selector(faceDetector: the image I want to pass in) forControlEvents:UIControlEven
[hangButton addTarget:self
action:@selector(faceDetector: the image I want to pass in)
forControlEvents:UIControlEventTouchUpInside];
您应该在把手按钮按下方法中触发事件。不预设参数,按钮按选择器传递一个参数,即发送事件的按钮
[hangButton addTarget:self
action:@selector(handleButtonPress:)
forControlEvents:UIControlEventTouchUpInside];
- (void) handleButtonPress:(id)sender {
UIImage * imageToFaceDetect = // get your image
[self faceDetector:imageToFaceDetect];
}
很高兴它能工作,如果它解决了您的问题,请确保选择作为答案!祝你的应用程序其余部分好运!