Mohit Deshpande
Mohit Deshpande

Reputation: 55237

Programmatically hook up events to methods?

Is there a way to hookup a button click to a method programmatically? It would be like imitating the CTRL+CLICK in Interface Builder.

Upvotes: 0

Views: 433

Answers (1)

Rob Jones
Rob Jones

Reputation: 4985

Check out UIControl, what UIButton inherits from. Specifically this method:

- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents

The action is the method you want to be invoked, and controlEvents represents the events that the action method should be called for, e.g. UIControlEventTouchUpInside for a click.

Upvotes: 3

Related Questions