Reputation: 3234
Added UIButton
to app
UIButton *playButton = [UIButton buttonWithType:UIButtonTypeCustom];
[playButton addTarget:self action:@selector(play:) forControlEvents:UIControlEventTouchUpInside];
UIImage *image = [UIImage imageNamed:@"play.png"];
[playButton setImage:image forState:UIControlStateNormal];
when i run the application it is crashing and message is UIButtonView unrecognized selector
Did exception breakpoint
Found that it is crashing at
[toolbar setItems:toolbarItems];
I think i m not adding UIButton
properly to toolbar
//Add buttons to the array
NSArray *toolbarItems = [NSArray arrayWithObjects: settingsButton, flexItem, rewind, flexItem, playButton, flexItem, pause, flexItem, modalBarButtonItem, nil];
[toolbar setItems:toolbarItems];
Anyideas to fix this one.
Thanks for help.
Upvotes: 1
Views: 140
Reputation: 8808
UIToolbar
contains instances of UIBarButtonItem
, not UIButton
. If you just need a custom image, try:
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(play:)];
// Build your array and setItems: using "item" among other objects
[item release];
Upvotes: 0
Reputation: 10782
The problem is that you can't directly stick a UIButton
into a UIToolBar
. You have to encapsulate the UIButton
in a UIBarButtonItem
's view and then stick your custom UIBarButtonItem
in the UIToolBar
. If you don't need a custom look or functionality, you may want to look into using a standard UIBarButtonItem
because it looks nice without much work on your part.
See Adding a UILabel to a UIToolbar for an example.
Upvotes: 1