1

I have the following code that adds a button of type UIBarButtonItem on UIToolbar (postoInfo):

UIImage *faceImage = [UIImage imageNamed:@"informazioni.png"];
UIButton *face = [UIButton buttonWithType:UIButtonTypeCustom];

[face addTarget:self action:@selector(press:) forControlEvents:UIControlEventTouchUpInside];

face.bounds = CGRectMake( 0, 0, 30, 30 );
[face setImage:faceImage forState:UIControlStateNormal];

buttonOne = [[UIBarButtonItem alloc] initWithCustomView:face];

NSArray *buttons = [NSArray arrayWithObjects: buttonOne, nil];

[postoInfo setItems: buttons animated:YES];

I would call a method when the button is pressed, I added, the following line, but does not work:

[face addTarget:self action:@selector(press:) forControlEvents:UIControlEventTouchUpInside];
Philipp Schlösser
  • 5,179
  • 2
  • 38
  • 52
Antilope
  • 443
  • 2
  • 6
  • 17

2 Answers2

3

You should provide correct frame property for UIButton, now it has CGRectZero:

face.frame = CGRectMake( 0, 0, 30, 30 ); 

Cocoa: What's the difference between the frame and the bounds?

Community
  • 1
  • 1
beryllium
  • 29,669
  • 15
  • 106
  • 125
0

The first thing that comes to my mind is that you are setting the action for the UIButton, but you are initializing the UIBarButtonItem with the UIButton's view. The action isn't saved in the view. You try setting the action for the UIBarButtonItem.

David Skrundz
  • 13,067
  • 6
  • 42
  • 66