将布尔值从 0 传递到 1 后没有任何反应

After passing Boolean Value from 0 to 1 nothing happened

我正在将 BOOL 值从 GameViewController 传递到 ChooseLevelViewController。如果 BOOL = 0 应该显示我 Button1PressedChooseLevel 中的正常图像。如果BOOL = 1我想要另一张图片。

我的代码:

ChooseLevel.h

@property (nonatomic) BOOL isSomethingEnabled;

ChooseLevel.m

if (_isSomethingEnabled) {


[_button1Pressed setImage:[UIImage imageNamed:@"buttonChanged.png"] forState:UIControlStateNormal];
}

GameView.m

#import "ChooseLevelViewController.h"

...

 ChooseLevelViewController *govc = [self.storyboard instantiateViewControllerWithIdentifier:@"chooseLevelViewController"];

        govc.isSomethingEnabled = 1;
        [self.finishAudio play];

        [self presentViewController:govc animated:NO completion:^(){
            [self.gameModel clearGameData];

        }];

我用NSLog测试,通过前的boolValue是0,通过后是1,工作正常。但是我的 ButtonIcon 没有改变

请定义一个更改按钮图像的方法 -

ChooseLevelViewController.h

-(void)loadButtonView;

loadButtonView 定义

ChooseLevelViewController.m

-(void)loadButtonView
{
    [_button1Pressed setImage:[UIImage imageNamed: _isSomethingEnabled?@"buttonChanged.png":@"Button1Pressed.png"] forState:UIControlStateNormal];
}


ChooseLevelViewController *govc = [self.storyboard instantiateViewControllerWithIdentifier:@"chooseLevelViewController"];

        govc.isSomethingEnabled = 1;
       // Call below method for button image change
        [govc loadButtonView];

        [self.finishAudio play];

        [self presentViewController:govc animated:NO completion:^(){
            [self.gameModel clearGameData];

        }];

希望这对您的问题有所帮助。