我将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并没有改变
答案 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];
}];
希望这会对你的问题有所帮助。