Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot access public variable of another class
    primarykey
    data
    text
    <p>I know this question is asked often, I've read so much on it but I still cant get it to work. Lets say I have two classes, FirstClass and SecondClass. FirstClass has a label and SecondClass wants to get the text of that label. Here is what I've done:</p> <pre><code>//FirstClass @interface FirstClass : UIViewController { @public UILabel *theLabel; } @property (strong, nonatomic) UILabel *theLabel; @implementation FirstClass @synthesize theLabel; //SecondClass #import "MainGameDisplay.h" @interface SecondClass : UIViewController { MainGameDisplay *mainGame; } @property (strong, nonatomic) UILabel *theSecondLabel; @implementation SecondClass -(void) thisMethodIsCalled { mainGame = [[FirstClass alloc] init]; self.theSecondLabel.text = mainGame.theLabel.text; NSLog(@"%@",mainGame.theLabel.text); //Output is '(Null)' } </code></pre> <p>theLabel.Text is not nil as it's being changed every second and is also displaying the label on the other controller which is running in the background whilst the SecondClass view is loaded. Could someone please point me to the write direction if I'm completely wrong, or show me some kind of example as to how this would be done. Thank you.</p> <hr> <p>EDIT:</p> <pre><code>@Implementation FirstClass @synthesize theLabel; - (void)viewDidLoad { [self superview]; [self startTickCount]; } -(void) startTickCount { timer = [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(timeChanger) userInfo:nil repeats:YES]; } -(void) timeChanger { theDay++; NSLog(@"%@",self.theLabel.text); if (theDay &lt;= 9) self.theLabel.text = [NSString stringWithFormat: @"0%i", theDay]; else self.theLabel.text = [NSString stringWithFormat: @"%i", theDay]; if (theDay &gt; 27) [self monthChanger]; } </code></pre> <p>That's pretty much it. The NSLog outputs the day as expected.</p>
    singulars
    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.
    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