Objective-C: How to call an instance method

I need to call a method that I defined as:

-(IBAction)next:(id)sender{ 
...

}

I want to call him -[UIViewController viewDidload]

How can I call this method programmatically?

+3
source share
1 answer
[self next:nil];
  • selfis an object receiving a message, assuming it -next:is defined in the same class as -viewDidLoad.
  • next: is the name of the message (method).
  • Since you are not using sender, pass an argument nilthat means "nothing."

If -next:defined in the application delegate, but -viewDidLoadin a controller of some kind, use

[UIApplication sharedApplication].delegate

to contact the application delegate. Thus, the statement becomes

[[UIApplication sharedApplication].delegate next:nil];
+7
source

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


All Articles