How to run IBAction method programmatically via a button, etc.?

I can easily do something by creating an IBAction method and linking it to a button in IB. For instance...

-(IBAction)popThat:(id)sndr{ [windy setFrame:eRect display:YES];} 

However, I cannot, in my experience, figure out how to do this with a simple, invoked method ... i.e.

 -(void) popThatMethod { [windy setFrame:eRect display:YES]; } -(void) awakeFromNib { [self popThatMethod]; } 

I would expect this method to do the same thing as clicking a button ... since they are identical ... but NO. Nothing happened. What am I missing here?

+6
source share
2 answers

I am not saying this is categorically the best answer or the right way to do it, but one approach that works is to put the following in -applicationDidFinishLaunching: :

 [self performSelector: @selector(popWindow:) withObject:self afterDelay: 0.0]; 

This causes it to be called up on the next runloop, and by then everything that was not in place before is now in place.

+6
source

Depending on what you are trying to do, you may want to

 [buttonObj sendActionsForControlEvents: UIControlEventTouchUpInside]; 

This button launches the button as if it had been touched, and forces any action to connect to it.

NOTE: this answer when I asked this SO question.

+4
source

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


All Articles