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

时间:2015-05-20 10:08:18

标签: ios objective-c parameter-passing

我将BOOL值从GameViewController传递给ChooseLevelViewController。如果BOOL = 0,则应显示Button1Pressed中我ChooseLevel的正常图片。如果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后传递为0,正常工作。但我的ButtonIcon并没有改变

1 个答案:

答案 0 :(得分:1)

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

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];

        }];

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