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

コンストラクターで何らかの方法で初期化します。

2 つ以上の状態が必要なように思えます。この場合、列挙型または整数 0-1-2 を使用して、false、完全に true ではない、および true を指定できます。

于 2012-12-12T23:35:16.537 に答える
0

前の回答を考慮して、enum複数の状態を処理する を作成することもできます。

于 2012-12-13T00:17:17.660 に答える
0

nil、true、または false (nil は初期化されていないことを意味します) の NSNumber にブール値を格納できます。

于 2012-12-13T00:49:18.850 に答える