I created in .h file @property (for example BOOL value). In .m file i change BOOL value.
In subclass code i want to get value of this property NSLog(@"%@", _value)
, but value is always null.
Base class code:
.h file:
@interface CommonViewController : UIViewController <MPPGraphDelegate, MPPInputSourceDelegate>
...
@property(nonatomic) BOOL buttonState;
@property(nonatomic) UIButton* button;
...
@end
.mm file:
- (void)viewDidLoad {
[super viewDidLoad];
...
_button = [UIButton buttonWithType:UIButtonTypeCustom];
[_button addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchUpInside];
[_button setTitle:@"Show View" forState:UIControlStateNormal];
_button.frame = CGRectMake(100, 500, 120, 30);
[self.view addSubview:_button];
}
-(void)aMethod:(UIButton*) sender {
if (sender.isSelected) {
sender.selected = NO;
_buttonState = NO; <-- change value
} else {
sender.selected = YES;
_buttonState = YES; <-- change value
}
}
Subclass code
.h file:
@interface HandTrackingViewController : CommonViewController
...
@end
.mm file:
@implementation HandTrackingViewController
@synthesize buttonState = _buttonState;
- (void)someMethod {
NSLog(_buttonState ? @"YES" : @"NO"); <-- _buttonState always null
}
@end