objective c - Why does address of self change when execution is in method didMoveToView? -


i have mac osx objective c project has me confused. xcode version 7.3, deployment target 10.11. project, built using ib, nothing more display animated sine wave, , sprite. i'd control speed of wave, , simplicity slow, medium, , fast, selected using radio matrix. there 4 source code files:

//appdelegate.h #import <cocoa/cocoa.h> @interface appdelegate : nsobject <nsapplicationdelegate> @property (weak) iboutlet nsmatrix *radioref; @end  //appdelegate.m #import "appdelegate.h" #import "sinewave.h"  @interface appdelegate () @property (weak) iboutlet nswindow *window; @property (weak) iboutlet skview *skview; @end  @implementation appdelegate - (void)applicationdidfinishlaunching:(nsnotification *)anotification {     // insert code here initialize application     [self.radioref selectcellwithtag:1];     skscene *scene;     cgsize size     = cgsizemake(360, 216);     scene           = [sinewave scenewithsize:size];     scene.scalemode = skscenescalemodefill;     [self.skview presentscene:scene]; }  - (void)applicationwillterminate:(nsnotification *)anotification {     // insert code here tear down application } @end  //sinewave.h #import <spritekit/spritekit.h> @interface sinewave : skscene @property (weak) iboutlet nswindow *window; @property (weak) iboutlet skview *skview; @property nsarray *walkframes;  - (ibaction)radioaction:(id)sender; @property (weak) iboutlet nsmatrix *radioref; - (void)      didmovetoview : (skview *) view; - (nsarray *) animationframesforimagenameprefix: (nsstring*) baseimagename framecount: (nsinteger) count; @end  //sinewave.m #import "sinewave.h" @implementation sinewave - (void)didmovetoview:(skview *)view {     cgfloat thisspeed = (cgfloat) self.radioref.selectedcell.tag;     if (thisspeed < 1.0)         thisspeed = 1.0;      self.walkframes = [self animationframesforimagenameprefix:@"sinwave" framecount:45];     // create sprite initial frame.     skspritenode *sprite = [skspritenode spritenodewithtexture:[self.walkframes objectatindex:0]];     sprite.position      = cgpointmake(cgrectgetmidx(self.frame), cgrectgetmidy(self.frame));     [self addchild:sprite];     skaction *animateframesaction = [skaction animatewithtextures:self.walkframes timeperframe:0.05];     [sprite runaction:[skaction repeatactionforever:animateframesaction]];     sprite.speed = thisspeed; }  - (nsarray *)animationframesforimagenameprefix: (nsstring*) baseimagename framecount: (nsinteger) count {     /* loads series of frames files stored in app bundle, returning them in array. */     nsmutablearray *array = [nsmutablearray arraywithcapacity:count];     (int = 1; i<= count; i++) {         nsstring *imagename = [nsstring stringwithformat:@"%@%03d.png",baseimagename, i];         sktexture *t = [sktexture texturewithimagenamed:imagename];         [array addobject:t];     }     return array; }  - (ibaction)radioaction:(id)sender {     cgsize size     = cgsizemake(360, 216);     skscene *scene  = [sinewave scenewithsize:size];     scene.scalemode = skscenescalemodefill;     [self.skview presentscene:scene]; } @end 

these connections: skview accessibility: link , title = none referencing outlets: skview -> sine wave , delegate accessibility references: link , title = none

the radio matrix outlets: delegate, formatter, menu, , nextkeyview = none sent actions: action -> sine wave , radioaction accessibility: link , title = none referencing outlets: radioref -> sine wave , delegate received actions: elements (performclick ... takestringvaluefrom) = none accessibility references: link , title = none

the object (of class sinewave) outlets: radio ref skview: sk view window: window referencing outlets: none received actions: radioaction -> radio ref

the code build , execute sprite works , display nice sine wave rolling across view (skview in file sinewave.h, line 6), @ 1 speed.

the radio matrix has tags slow=1, medium=3, , fast=6, in hope of producing thisspeed values of 1.0, 3.0, , 6.0. has me perplexd radioref has value nil while execution in method didmovetoview. how can/should obtain selected cell of radio matrix in method didmovetoview?

why address of self change when execution in method didmovetoview?

it doesn't, have 2 or more distinct objects.

the method scenewithsize: call in applicationdidfinishlaunching: creates new object. if have connected iboutlets in sinewave.h in ib have sinewave object in xib - you've got 2 objects.

hth


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -