开发者

Setting a button's target/action and passing a particular string to the action [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜