Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-08-2010, 06:03 AM   #1 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 55
Default How to call a method when clicking a UIToolBar Item

Hi,

Can anyone please guide me on the right process on calling a method when a UIToolbar item is clicked?

Here's my code:
UIButton *cstCommunications = [[UIButton alloc] init]; [cstCommunications setTitle:@"Communications" forState:UIControlStateNormal];
cstCommunications.backgroundColor = [UIColor redColor];
[cstCommunications setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
cstCommunications.titleLabel.font = [UIFont systemFontOfSize:10.0f];
[cstCommunications setFrame:CGRectMake(0.0f, 0.0f, 80.0f, 15.0f)];


UIBarButtonItem *btnCommunications = [[UIBarButtonItem alloc] initWithCustomView:cstCommunications];
btnCommunications.action = @selector(testAction;
btnCommunications.target = self;

But when i click on the tool bar item, the code does not go to testAction method...Am I missing something here? Any help would be greatly appreciated. Thanks again.
tobs is offline   Reply With Quote
Old 02-08-2010, 09:40 AM   #2 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

Try putting the target/action on the UIButton.
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 02-08-2010, 08:47 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 55
Default

Quote:
Originally Posted by BrianSlick View Post
Try putting the target/action on the UIButton.
UIButton has no target/action properties.
tobs is offline   Reply With Quote
Old 02-08-2010, 08:48 PM   #4 (permalink)
Emphasizing Fundamentals
 
BrianSlick's Avatar
 
Join Date: Jul 2009
Location: NoVA / DC Area
Age: 36
Posts: 7,129
Default

Learn about inheritance.

addTarget:action:forControlEvents:
__________________
BriTer Ideas LLC - Code review, consulting, development. PM for pricing.

SlickShopper 2 | Free NSLog utility | Leave a PayPal donation.

Are you a newbie? Things you should read:
BrianSlick is offline   Reply With Quote
Old 02-09-2010, 12:43 AM   #5 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 55
Default

Quote:
Originally Posted by BrianSlick View Post
Learn about inheritance.

addTarget:action:forControlEvents:
awesome! thanks!
tobs is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 266
20 members and 246 guests
ADY, AragornSG, Bertrand21, Dani77, Dattee, Duncan C, fkmtc, HDshot, HemiMG, iDifferent, JasonR, macquitzon216, mer10, prchn4christ, Rudy, sacha1996, sneaky, spiderguy84, Sunny46, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,231
Posts: 380,768
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:12 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0