I am doing this to change the UIButton image, here all “switches” are IBOutlets of UIButton,
-(IBAction)userselect:(id)sender
{
UIButton *btnTagcatcher =(UIButton * )sender;
if(btnTagcatcher.tag == 1)
{
if(btnimgflag1 == 0)
{
NSString* path = [[NSBundle mainBundle] pathForResource:@"check-box-withtick-1n1"
ofType:@"png"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:path];
[switch1 setImage:image forState:UIControlStateNormal];
NSString* path1 = [[NSBundle mainBundle] pathForResource:@"check-box-withouttickn1"
ofType:@"png"];
UIImage *image1 = [[UIImage alloc] initWithContentsOfFile:path1];
[switch2 setImage:image1 forState:UIControlStateNormal];
[switch3 setImage:image1 forState:UIControlStateNormal];
[switch4 setImage:image1 forState:UIControlStateNormal];
btnimgflag2 = 0;
btnimgflag3 = 0;
btnimgflag4 = 0;
btnimgflag1 = 1;
}
else if(btnimgflag1 == 1)
{
NSString* path = [[NSBundle mainBundle] pathForResource:@"check-box-withouttickn1"
ofType:@"png"];
UIImage *image = [[UIImage alloc] initWithContentsOfFile:path];
//[switch1 setImage: image];
[switch1 setImage:image forState:UIControlStateNormal];
btnimgflag1 = 0;
}
But some times (usually when pressed first time) the button image does not changes when tapped.
I have no idea, what is going on here, plz. Guide me in this, thanx in advance.
Regards Saad.
Can you change this condition
else if(btnimgflag1 == 1)to simpleelsestatement. Because in theifpart you are assigning btnimgflag1 to be 1btnimgflag1 = 1;. Just my guess, and I had exactly the same problem!! If that didn’t help out!!IBOutlet connectionsshould be the problem!!