0
votes

I have a MKMapView with a number of annotations representing stores. When the user taps on an annotation I present a custom annotation view. This view contains a favourite button, that adds the store to the user's favourites.

If the user presses this button it changes its backgroundImage property to another image indicating its status as a favourite store.

The problem that is occurring is that the image does not change when the user taps it. It is calling the method and adding the store to its favourites but it is not changing the image. If the user dismisses the callout and then taps the annotation again to view the callout, the button is then presenting the correct background image.

This problem only occurs on a iOS7 device but will work perfectly on an iOS7 simulator and iOS8 simulator/device.

Any help would be great, thanks.

2

2 Answers

0
votes

First set 2 different images for two states of button.

[btn setBackgroundImage:img1 forState:UIControlStateNormal];
[btn setBackgroundImage:img2 forState:UIControlStateSelected];

then on buttonPress event

set

button.selected = !button.selected
0
votes

are you using code like this one for change an image-

     [btn setBackgroundImage:img1 forState:UIControlStateNormal];
    [btn setBackgroundImage:img1 forState:UIControlStateSelected];
    [btn setBackgroundImage:img1 forState:UIControlStateHighlighted];

and try this one line when btnpressed

[btn setNeedsDisplay];