简体   繁体   English

将参数传递给选择器

[英]Passing parameters into a selector

I have an UIButton that is subview on an UIView. 我有一个UIButton是UIView的子视图。 When the button is pressed, my app is supposed to pass a captured image into a function called by the @selector. 按下按钮时,我的应用程序应该将捕获的图像传递给@selector调用的函数。 However, my research shows me that I am not able to pass anything to the function with the selector of the UIButton. 但是,我的研究表明,我无法使用UIButton的选择器向函数传递任何内容。 How can I go around this? 我怎么能绕过这个?

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

You should trigger your events within a handleButton press method. 您应该在handleButton按下方法中触发事件。 You don't preset arguments, buttonPress selectors pass one argument, the button that is sending the event. 您没有预设参数,buttonPress选择器传递一个参数,即发送事件的按钮。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM