Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I access variable values from one view controller in another?
    primarykey
    data
    text
    <p>I have an integer variable (<strong>time</strong>) in one view controller whose value I need in another view controller. Here's the code:</p> <p><strong>MediaMeterViewController</strong></p> <pre><code>// TRP - On Touch Down event, start the timer -(IBAction) startTimer { time = 0; // TRP - Start a timer timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateTimer) userInfo:nil repeats:YES]; [timer retain]; // TRP - Retain timer so it is not accidentally deallocated } // TRP - Method to update the timer display -(void)updateTimer { time++; // NSLog(@"Seconds: %i ", time); if (NUM_SECONDS == time) [timer invalidate]; } // TRP - On Touch Up Inside event, stop the timer, decide stress level, display results -(IBAction) btn_MediaMeterResults { [timer invalidate]; NSLog(@"Seconds: %i ", time); ResultsViewController *resultsView = [[ResultsViewController alloc] initWithNibName:@"ResultsViewController" bundle:nil]; [self.view addSubview:resultsView.view]; } </code></pre> <p>And in ResultsViewController, I want to process <strong>time</strong> based on its value</p> <p><strong>ResultsViewController</strong></p> <pre><code>- (void)viewDidLoad { if(time &lt; 3) {// Do something} else if ((time &gt; 3) &amp;&amp; (time &lt; 6)) {// Do something else} //etc... [super viewDidLoad]; } </code></pre> <p>I'm kind of unclear on when @property and @synthesize is necessary. Is that the case in this situation? Any help would be greatly appreciated.</p> <p>Thanks! Thomas</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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