ios - Objective-C: self = nil doesn't set instance to null value -
i've got next code, pretty simple:
//secondviewcontroller.m if(contentrvcontroller==nil){ contentrvcontroller = [[contentview alloc] initwithnibname:@"contentview" bundle:nil]; //contentview custom uiviewcontroller .... [self.view addsubview:contentrvcontroller.view]; } else{ contentrvcontroller.view.hide = yes; [contentrvcontroller release]; contentrvcontroller = nil; }
basically, when code launched button, if uiviewcontroller not exist, create 1 , display (it meant displayed on main bigger desktop view, secondviewcontroller view). if opened, close , remove free resources.
now, contentrvcontroller instance of contentview, custom uiviewcontroller. has it's own close uibutton ibaction this:
//contentview.m - (ibaction) closeview { self.view.hidden = yes; [self release]; self = nil; }
now, when triggered secondviewcontroller, releasing contentrvcontroller works (or seems me), view appears , disappears. when contentview close button tapped closes view, when trying open again if(contentrvcontroller==nil)
returns false
, have tap twice button execute in order display again contentview.
it seems me self = nil;
works different contentrvcontroller = nil;
although supposed both points same place, , im lost this.
¿any idea? cheers méxico
they work same way, they're not doing think do. =
not affect object; affects variable pointing object. setting 1 variable point nil won't change value of other variables in program. similarly:
int = 5; int b = a; b = 6; printf("a %d , b %d\n", a, b);
this print "a 5 , b 6" — because setting b new value doesn't change value of a.
Comments
Post a Comment