iphone – Objective-C:UIButton图像不会改变

我这样做是为了改变UIButton图像,这里所有的“开关”都是UIButton的IBOutlets,

-(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;
            }

但有时(通常在第一次按下时)按钮图像在点击时不会改变.

我不知道,这里发生了什么,PLZ.在此提前指导我,而不是提前.

关心萨阿德.

最佳答案 如果(btnimgflag1 == 1)改为简单的else语句,你能改变这个条件.因为在if部分你将btnimgflag1指定为1 btnimgflag1 = 1;.只是我的猜测,我有完全相同的问题!如果那没有帮助!! IBOutlet连接应该是问题!!

点赞