tomhat
tomhat

Reputation: 1

How to add action?

Can I add 2 actions for a UIBarButtonItem?
First, I'm using a UIBarButtonItem. It looks like.

 button = [[UIBarButtonItem alloc] initWithTitle:@"hoge"
                                           style:UIBarButtonItemStylePlain
                                          target:self
                                          action:@selector(method)];

Next, I want to add it action. How to add action?

Upvotes: 0

Views: 72

Answers (1)

Mykola Denysyuk
Mykola Denysyuk

Reputation: 1985

You cant add more actions to UIBarButton, but to UIButton you can:

UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:target action:@selector(action1) forControlEvents:UIControlEventTouchDragInside];
[button addTarget:target action:@selector(action2) forControlEvents:UIControlEventTouchDragInside];
[button addTarget:target action:@selector(action3) forControlEvents:UIControlEventTouchDragInside];

UIBarButtonItem* barButton = [[UIBarButtonItem alloc] initWithCustomView:button];

Upvotes: 2

Related Questions