Setting a button's target/action and passing a particular string to the action [closed]
I create a UIButton
and add a selector开发者_开发知识库 with an NSString
argument, but it gives a syntax error.
NSString*title=@"abc";
[backViewButton addTarget:self
action:@selector(buttonClicked:WithString:title)
forControlEvents:UIControlEventTouchUpInside];
You can't pass arguments when you use @selector
.
@selector(buttonClicked:WithString:title)
// This here is invalid^^
That operator can only be used on a method name; the selector you get from it is later used to call the method, at which point arguments can be passed.
Best guess without seeing the error is you forgot to put a colon at the end of your selector. Probably ought to be @selector(buttonClicked:WithString:title:)
. Unless, as Josh Caswell suggested, you are for some reason trying to create a selector with an argument... that would be pretty strange, and incorrect.
精彩评论