I need to call a method I have defined as:
-(IBAction)next:(id)sender{
...
}
I want to call it in -[UIViewController viewDidload]
How can I call this method programmatically?
In Objective-C, there are instances, which are the objects that you create and use, and there are (semi-hidden) objects which are class objects, and which are created by the compiler. The class object is where the methods for the class are stored; each instance holds only its own data (i.e., instance variables).
Instance methods are the most common type of method, because you'll most commonly be telling a specific object to perform some action. Class methods can be useful, however, when there's no contextual data needed in the method, and it can theoretically be implemented and run on any generic object.
[self next:nil];
self
is the object receiving the message, assuming -next:
is defined in the same class as -viewDidLoad
.next:
is the name of the message (method).sender
, pass the argument nil
, meaning "nothing".If -next:
is defined in the App delegate but -viewDidLoad
in some view controller, use
[UIApplication sharedApplication].delegate
to refer to the app delegate. So the statement becomes
[[UIApplication sharedApplication].delegate next:nil];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With