How can I get a default value in some instances but not others?
Posted
by
Connor Wagner
on Stack Overflow
See other posts from Stack Overflow
or by Connor Wagner
Published on 2012-12-13T20:01:07Z
Indexed on
2012/12/14
5:03 UTC
Read the original article
Hit count: 148
iphone
|objective-c
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? 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; }
The problem that it is redefined when the ViewDidLoad runs... I need a statement that will not redefine when the ViewDidLoad runs. 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 tried putting the code in the gameLoop into the ViewDidLoad, but it had the same effect. When moveOver was false, the computerMoveSpeed and the playToInt were both seemingly 0. 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?
THIS IS A DIFFERENT ISSUE THAN THE THREE BOOLEAN VALUES QUESTION
© Stack Overflow or respective owner