The solution can be very simple if you look at it. Store the global UIButton, not the local one. This helps, because when the web request returns a response, the button must be present in the scope and not be deleted from memory.
Therefore use
self.myButton = [UIButton buttonWithType:UIButtonTypeCustom]; [self.myButton setBackgroundImage:[UIImage imageNamed:@"unread.png"] forState:UIControlStateNormal];
OR
[self.myButton setImage:[UIImage imageNamed:@"unread.png"] forState:UIControlStateNormal];
And, if you check the button click, follow these steps:
-(IBAction)checkForMsgCount: (id)sender { UIButton *buttonObj = (UIButton*)sender; [buttonObj setBackgroundImage:[UIImage imageNamed:@"unread.png"] forState:UIControlStateNormal]; }
This is a background image change for a button that responds to a function.
source share