Note that there are some explanatory texts on larger screens.

plurals
  1. POViewDidLoad being called before initWithNibName?
    text
    copied!<p>I'm having the strangest error, and i hope someone could help me. Here is the code when I create a view controller and push it to navigationController. the problem is passing the random variable to the new view controller. I tried passing it in the init method and also passing it with the line commented below.</p> <pre><code> MultipleBet *multipleBet = [[MultipleBet alloc] initWithMaxNumber:numbers andMaxStars:stars andRandom:self.random]; NSLog(@"RANDOM1: %d", self.random); //[multipleBet setRandom:self.random]; UIBarButtonItem *backButton = [[[UIBarButtonItem alloc] init] autorelease]; backButton.title = @"Voltar"; self.navigationItem.backBarButtonItem = backButton; [self.navigationController pushViewController:multipleBet animated:YES]; [multipleBet release]; </code></pre> <p>However when i access the random variable in the viewDidLoad of the MultipleBet, it's always FALSE.</p> <p>here is the code of the MultipleBet:</p> <pre><code>- (id)initWithMaxNumber:(int)maxNumbers andMaxStars:(int)maxStars andRandom:(BOOL)isRandom { self = [super initWithNibName:@"MultipleBet" bundle:[NSBundle mainBundle]]; ... self.random = isRandom; NSLog(@"RANDOM2: %d", self.random); NSLog(@"RANDOM2.1: %d", isRandom); return self; } </code></pre> <p>and here is the code of the viewDidLoad:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; NSLog(@"RANDOM2.2: %d", self.random); } </code></pre> <p>i declare the variable and property like this:</p> <pre><code>BOOL random; @property (nonatomic) BOOL random; </code></pre> <p>and the output is always:<br> RANDOM2.2: 0<br> RANDOM2: 1<br> RANDOM2.1: 1<br> RANDOM1: 1<br></p> <p>Why is the NSLog from the viewDidLoad being outputted before all the others? it should be the last... Could it be because of my custom init method? I call the [super init], so it shouldn't be a problem...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload