Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to access a variable's value from one class, if the variable is defined in another? (Objective-C)
    primarykey
    data
    text
    <p>I have two pairs (.m and .h) of files. In one's interface section, I've defined a global BOOL variable. I need to get it's value in another class. How can I do it? (I can't make one class a subclass of another).</p> <p>In one file I have </p> <pre><code>@interface TabBarRotation : UITabBarController { BOOL portrait; } @end @implementation TabBarRotation - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return YES; } - (void):(UIInterfaceOrientation) interfaceOrientation { if (interfaceOrientation == UIInterfaceOrientationPortrait||interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { portrait=YES; } else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) { portrait=NO; } } @end </code></pre> <p>And in another's @implementation I have </p> <pre><code>- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event { if(portrait==YES) { CalcPortraitViewController *CalcPortraitController; CalcPortraitController = [[CalcPortraitViewController alloc] initWithNibName:@"CalcPortraitView" bundle:nil]; CalcPortraitController.title=@"Калькулятор"; CalcPortraitController.hidesBottomBarWhenPushed=YES; [self.navigationController pushViewController:CalcPortraitController animated:NO]; [self.navigationController setNavigationBarHidden:YES animated:NO]; } else if (portrait==NO) { CalcLandscapeViewController *CalcLandscapeController; CalcLandscapeController = [[CalcLandscapeViewController alloc] initWithNibName:@"CalcLandscapeView" bundle:nil]; CalcLandscapeController.title=@"Калькулятор"; CalcLandscapeController.hidesBottomBarWhenPushed=YES; [self.navigationController pushViewController:CalcLandscapeController animated:NO]; [self.navigationController setNavigationBarHidden:YES animated:NO]; } } </code></pre>
    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