Retrieve UIToolBarItem

Hello EE Mac,

Refering this question for my new question.

I need to modify a uiToolBarItem but this time is when I touch another toolBarItem. In other words, I have Left and right arrows that swap images and at each images I need to update the image of a thumb up or a thumb down depending on the database is the Thumb saved at bool 0 or 1  (1 is up  0 is down)

So I dont have the sender of the thumb barItem
how can I recall the thumbItem for another toolbarItem press?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

just keep a reference to you UIBarButtonItem in your ViewController, if your building the view as a NIB then simply define an outlet as a property in the code and link it to the item.  your building the view in code then create a property and assign it.

once you have done this you can manipulate the that bar item whenever you want.
PhilippeRenaudAuthor Commented:
I am building everything in code behind, does it make a difference?
no not at all, just create a property in the view controller class and assign the UIBarButtonItem to it.  the when you get the message from the other button simply use the property and change the image.
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

PhilippeRenaudAuthor Commented:
Ok so I create a UIBarbuttonItem property IBOutlet

I was going to say I assign my draging the line on design view but I cant do that, I am not sure what you mean by Assign ?
PhilippeRenaudAuthor Commented:
I assign by draging*
PhilippeRenaudAuthor Commented:
Here's what I do, I am having an error (I think I know why, but not sure on how to do everything right) :

    UIBarButtonItem *_likeMe;
@property(nonatomic, retain) UIBarButtonItem *likeMe;

on .m   :

    if (a == @"0"){
        [(UIButton*)_likeMe setImage:[UIImage imageNamed:@"240x320-thumbs-up.png"] forState:UIControlStateNormal];
    } else {
        [(UIButton*)_likeMe setImage:[UIImage imageNamed:@"320x480-thumbs-down.png"] forState:UIControlStateNormal];  

this is causing error : -[UIBarButtonItem setImage:forState:]: unrecognized selector sent to instance 0x7181300
2011-10-04 12:50:43.518 Fashion 8[514:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIBarButtonItem setImage:forState:]: unrecognized selector sent to instance 0x7181300'

I understand that _likeMe is a UIBarButtonItem and not a UIButton but the problem is that my buttonItem _likeMe has a UIImage and a UIButton because otherwise I couldnt put a custom colored image on it.

any idea?
humm, can you post the code where you are creating the UIBarButtonItem and add it to the toolbar.
PhilippeRenaudAuthor Commented:
   UIImage *likeImage = [UIImage imageNamed:@"240x320-thumbs-up.png"];
    UIButton *likeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [likeButton setImage:likeImage forState:UIControlStateNormal];
    [likeButton addTarget:self action:@selector(likeButtonHit:) forControlEvents:UIControlEventTouchDown];
    likeButton.frame = CGRectMake(0, 0, likeImage.size.width, likeImage.size.height);
    UIBarButtonItem *like = [[UIBarButtonItem alloc] initWithCustomView:likeButton];


            [self setToolbarItems:[NSArray arrayWithObjects:fixedLeft, flex, left, fixedCenter, right, flex, like, action, nil]];


[like release];
try this

UIButton *tmpButton = (UIButton*)_likeMe.customView;
if (a == @"0"){
    [tmpButton setImage:[UIImage imageNamed:@"240x320-thumbs-up.png"] forState:UIControlStateNormal];
} else {
    [tmpButton setImage:[UIImage imageNamed:@"320x480-thumbs-down.png"] forState:UIControlStateNormal];   

Open in new window

remember the UIButton is contained in the customView property of the UIBarButtonItem, the UIBarButtonItem does not become a UIButton...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PhilippeRenaudAuthor Commented:
Ok I tried, I have no error but the image does not change...

and my a variable is fine in NSLog  sometimes its  "0"  sometimes its "1"

PhilippeRenaudAuthor Commented:
Wait a second... I just saw it alwasy goes in the ELSE Statement..

looks like its doesnt like the a == @"0"

im used to .NET  lol
PhilippeRenaudAuthor Commented:
Thanks, I used  equalToString for my other problem.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Swift Programming

From novice to tech pro — start learning today.