views:

60

answers:

1

Hi all,

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?

+3  A: 
[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).
  • Since you don't use 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];
KennyTM
Excuse my ignorance (still learning), you can't just use `[self next]` with no params?
Yar
@yar: No. Also, in ObjC `-next:` and `-next` are *different* methods (the colons are significant).
KennyTM
Thanks @KennyTM, that helps. Why can't all these languages just be the same :)?!
Yar