views:

108

answers:

1

Say for instance I have an IBAction that is hooked up to a button in interface builder.

- (IBAction)functionToBeCalled:(id)sender
{
   // do something here   

}

Within my code, say for instance in another method, what is the best way to call that IBAction?

If I try to call it like this, I receive an error:

[self functionToBeCalled:];

But, if I try to call it like this (cheating a bit, I think), it works fine:

[self functionToBeCalled:0];

What is the proper way to call it though?

+5  A: 

The proper way is either

  • [self functionToBeCalled:nil] to pass a nil sender, indicating that it wasn't called through the usual framework, or
  • [self functionToBeCalled:self] to pass yourself as the sender, which is also correct.

Which one to chose depends on what exactly the function does, and what it expects the sender to be.

calmh
perfect, thank you!
iWasRobbed