4

画像を変更するためにこれを行っています。ここでは、UIButtonすべての「スイッチ」IBOutletsUIButton

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

しかし、場合によっては(通常は最初に押されたとき)、タップしてもボタンの画像が変化しません。

ここで何が起こっているのかわかりません。これで私を案内してください、事前に感謝します。

よろしくサード。

4

2 に答える 2

1

else if(btnimgflag1 == 1)この条件を簡単なelseステートメントに変更できますか。そのif部分で btnimgflag1 を 1 に割り当てているためbtnimgflag1 = 1;です。私の推測ですが、まったく同じ問題がありました!! それが役に立たなかったら!! IBOutlet connections問題になるはずです!!

于 2012-08-06T07:36:09.413 に答える
1

コードをデバッグして、ボタンの正しいタグを取得しているかどうかを確認してください。私はあなたが説明したものを正確に実装し、コードをコピーして貼り付けましたが、機能しませif(btnTagcatcher.tag == 1)if(btnTagcatcher.tag == 0)。これで動作するようになりました。これを確認してみてください。

これに問題がある場合は、メール ID を送信してください。完全なコードをお送りします。

于 2012-08-06T07:23:25.567 に答える