Kyuubi
Kyuubi

Reputation: 1240

UIImageView for a UIButton does not change

I have the following IBOutlet Action

.
.
if(!isWishlisted)
        {
            isWishlisted = true;
            plistPath = [[NSBundle mainBundle] pathForResource:@"InYourWishlist" ofType:@"png"];
            addToWishListButton.imageView.image = [UIImage imageWithContentsOfFile:plistPath];
            NSLog(@"Set Image with InYourWishlist");
        }
        else
        {
            isWishlisted = false;
            plistPath = [[NSBundle mainBundle] pathForResource:@"Add to Wishlist" ofType:@"png"];
            addToWishListButton.imageView.image = [UIImage imageWithContentsOfFile:plistPath];
            NSLog(@"Set Image with Add To Wishlist");
        }
.
.

Initially , on view load , this is executed once

isWishlisted = false;

And on the "mainSoryBoard" , the image for the " addToWishListButton" is set to "Add to Wishlist.png".

On first two clicks (few seconds apart) , I get the following Log Output :

2012-10-28 21:16:28.420 Movie Rental[92512:c07] Set Image with InYourWishlist
2012-10-28 21:16:31.596 Movie Rental[92512:c07] Set Image with Add To Wishlist

But the problem is that the image "InYourWishlist.png" appears for an instant on the button , and then it changes back to the previous image.

What seems to be the problem ? There is no other place in the code where I am accessing the button "addToWishListButton".

Upvotes: 0

Views: 263

Answers (1)

Kyuubi
Kyuubi

Reputation: 1240

Got it working using

[addToWishListButton setImage:[UIImage imageWithContentsOfFile:plistPath] forState:UIControlStateNormal];

Upvotes: 2

Related Questions