How to call id sender function from another function?

In the following code example, I want to be able to call backgroundTap from another btnSubmitLoginPassword function. Which parameter should pass?

-(IBAction) backgroundTap:(id)sender{ [userName resignFirstResponder]; [password resignFirstResponder]; } -(IBAction) btnSubmitLoginPassword{ [self backGroundTap:?????????] [self validate]; } 
+6
source share
4 answers

PengOne's answer is good, but the exact answer to your question is: pass nil for the sender parameter:

 [self backgroundTap:nil]; 
+14
source

You are not using sender in action, so why not just leave it?

 -(IBAction) backgroundTap{ [userName resignFirstResponder]; [password resignFirstResponder]; } -(IBAction) btnSubmitLoginPassword{ [self backGroundTap]; [self validate]; } 
+5
source

you are not using id value in method

  -(IBAction) backgroundTap:(id)sender { [userName resignFirstResponder]; [password resignFirstResponder]; } 

use as instead

  -(IBAction) backgroundTap { [userName resignFirstResponder]; [password resignFirstResponder]; } 

and then do it like

  -(IBAction) btnSubmitLoginPassword{ [self backGroundTap]; [self validate]; } 

if you want to change / access the property of the sender, then you must use the (id) of the sender

+2
source

Typically, the sender parameter is a UIView or any other object that generates an event. In this case, it would therefore be to use self as the sender.

+2
source

Source: https://habr.com/ru/post/890653/


All Articles