R. Dewi
R. Dewi

Reputation: 4271

set action using method from another class in objective C

is it possible to set an action using method from another class?? Is there any example code??

Upvotes: 1

Views: 1002

Answers (1)

nacho4d
nacho4d

Reputation: 45098

action of a button for example?

programmatically will be something like:

[button addTarget:objectX action:@selector(methodImplementedInObjectX:) forControlEvents:UIControlEvent...];

this can be written anywhere, in your view controller, inside the view itself , etc as long as you have a reference to the button. ;)

EDIT

performSelector:... methods makes the receiver perform a method. So, in your case it would be:

[objectName performSelector:@selector(methodName:) withObject:nil];

because self won't perform anything right? the one who is performing something will be objectName

Upvotes: 3

Related Questions