1

I am making an iPhone app and want to use an 'if' statement and a boolean to set default values in some instances but not others... is this possible?

Are there alternative options if it is not possible?

EDIT: In the MainViewController.m I have:

@interface MainViewController (){
    BOOL moveOver;
}
[...]
- (void)viewDidLoad
{
    [super viewDidLoad];
    _label.text = [NSString stringWithFormat:@"%i", computerSpeed];
    }
}
[...]
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller
{
    [self dismissViewControllerAnimated:YES completion:nil];
    moveOver = true;    
}

EDIT: The problem that it is redefined when the ViewDidLoad still persists... I need a statement that will not redefine when the ViewDidLoad runs (sorry for the unclarity)

EDIT: I have something that I feel like is much closer to working...

In the ViewDidLoad I have:

if (playToInt != 10  || computerMoveSpeed != 3) {   
    moveOver = TRUE;
}

which connects to my created method, gameLoop. It has

if (moveOver == false) {
    computerMoveSpeed = 3;        
    playToInt = 10;    
}

I have two UITextFields and typed 10 and 3 in them... does this not set it to the default? It seems to set the default to 0 for both, how do I change this?

4

3 回答 3

2

在构造函数中以一种或另一种方式初始化它。

听起来您想要两个以上的状态,在这种情况下,您可以使用枚举甚至整数 0-1-2 来表示错误、不完全正确和正确。

于 2012-12-12T23:35:16.537 回答
0

考虑到前面的答案,您还可以创建一个enum来处理多个状态。

于 2012-12-13T00:17:17.660 回答
0

您可以将布尔值存储在 NSNumber 中,该值可以是 nil、true 或 false(nil 表示未初始化)。

于 2012-12-13T00:49:18.850 回答