{"id":5166,"date":"2014-03-30T19:19:13","date_gmt":"2014-03-30T19:19:13","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/for-uibutton-how-to-pass-multiple-arguments-through-selector-duplicate-collection-of-common-programming-errors\/"},"modified":"2014-03-30T19:19:13","modified_gmt":"2014-03-30T19:19:13","slug":"for-uibutton-how-to-pass-multiple-arguments-through-selector-duplicate-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/for-uibutton-how-to-pass-multiple-arguments-through-selector-duplicate-collection-of-common-programming-errors\/","title":{"rendered":"For UIButton how to pass multiple arguments through @selector [duplicate]-Collection of common programming errors"},"content":{"rendered":"<p>Short answer: You don&#8217;t. The <code>@selector<\/code> there tells the button what method to call when it gets tapped, not the arguments that it should pass to the method.<\/p>\n<p>Longer answer: If you know when you&#8217;re creating the button what the argument is going to be, then you can wrap it up like this:<\/p>\n<pre><code>\/\/ In loadView or viewDidLoad or wherever:\n[imageButton addTarget:self action:@selector(imageButtonTapped:) forControlEvents:UIControlEventTouchUpInside];\n\n... later ...\n\n- (void)imageButtonTapped:(id)sender\n{\n    [self doStuffToMyImageWithArgument:10];\n}\n\n- (void)doStuffToMyImageWithArgument:(NSInteger)argument\n{\n    ... do what you gotta do ...\n<\/code><\/pre>\n<p>If you don&#8217;t know, then you probably want to save the argument to a variable somewhere.<\/p>\n<pre><code>\/\/ In your @interface\n@property (nonatomic, assign) NSInteger imageStuffArgument;\n\n... later ...\n\n\/\/ In loadView or viewDidLoad or wherever:\n[imageButton addTarget:self action:@selector(imageButtonTapped:) forControlEvents:UIControlEventTouchUpInside];\n\n... later ...\n\n- (void)respondToWhateverChangesTheArgument\n{\n    self.imageStuffArgument = 10;\n}\n\n... later ...\n\n- (void)imageButtonTapped:(id)sender\n{\n    [self doStuffToMyImageWithArgument:self.imageStuffArgument];\n}\n\n- (void) doStuffToMyImageWithArgument:(NSInteger)argument\n{\n    ... do what you gotta do ...\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Short answer: You don&#8217;t. The @selector there tells the button what method to call when it gets tapped, not the arguments that it should pass to the method. Longer answer: If you know when you&#8217;re creating the button what the argument is going to be, then you can wrap it up like this: \/\/ In [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5166","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5166"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5166\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}