ios - How detect change status @property objective c -
i've little problem , don't know how solve it:
i've develop little game in skspritekit , detect when bool @property (play/pause) change status. i've viewcontroller (uiviewcontroller class) superviewcontroller of game, singleton called backgroundcommon (nsobject class) include @property bool pause , stored methods common background, , skscenes write @proprety of backgroundcommon class.
when skscene change or button press... system write @property . find solution apparently works nothing works me. link official documentation
if follow guide problems are:
backgroundcommon class not instancied because class used store methods
for me observer viewcontroller , here must instace backgroundcommon class(i'm not sure)
is viewcontroller bank object (like official documentation)?
is backgroundcommon person object (like official documentation)?
i tried on viewcontroller:
- (void)viewdidload { [super viewdidload]; backgroundcommon *bkc = [[backgroundcommon alloc] init]; [bkc addobserver:self forkeypath:@"pause" options:nskeyvalueobservingoptionnew context:null]; }
then added (even on view controller):
-(void) observevalueforkeypath:(nsstring *)keypath ofobject:(id)object change:(nsdictionary *)change context:(void *)context { nslog (@"working"); }
i tried change @property message appear in console:
an instance 0xc216b40 of class backgroundcommon deallocated while key value observers still registered it. observation info leaked, , may become mistakenly attached other object. set breakpoint on nskvodeallocatebreak stop here in debugger. here's current observation info: ( context: 0x0, property: 0xc218a40>
i don't understang put , how can use it... please me
you need put observer inside backgroundcommon:
- (void)viewdidload { [super viewdidload]; [self addobserver:self forkeypath:@"self.pause" options:nskeyvalueobservingoptionnew context:nil]; } -(void)observevalueforkeypath:(nsstring *)keypath ofobject:(id)object change:(nsdictionary *)change context:(void *)context { nslog (@"working"); }
later, value can use in other controller:
backgroundcommon *bkc = [[backgroundcommon alloc] init]; nslog(@"pause value: %i", bkc.pause");
Comments
Post a Comment