J'ai deux paires (.m et .h) de fichiers. Dans la section interface, j'ai défini une variable globale BOOL. J'ai besoin d'avoir de la valeur dans une autre classe. Comment puis-je le faire? (Je ne peux pas faire d'une classe une sous-classe d'une autre).Comment accéder à la valeur d'une variable d'une classe, si la variable est définie dans une autre classe? (Objective-C)
Dans un fichier je
@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
Et je le @implementation d'un autre
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if(portrait==YES) {
CalcPortraitViewController *CalcPortraitController;
CalcPortraitController = [[CalcPortraitViewController alloc]
initWithNibName:@"CalcPortraitView" bundle:nil];
[email protected]"Калькулятор";
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];
[email protected]"Калькулятор";
CalcLandscapeController.hidesBottomBarWhenPushed=YES;
[self.navigationController pushViewController:CalcLandscapeController
animated:NO];
[self.navigationController setNavigationBarHidden:YES animated:NO];
}
}
Veuillez fournir un exemple de code pour clarifier votre question. – fbrereto
En particulier, comment peut-il être à la fois une interface globale et dans la classe? –