objective c - ios - does it reuse previously allocated object? -


i wondering why object allocating reused address used.

the scenario this:

  • appdelegate created loginviewcontroller (we call guy, log1)
  • after logging in log1, created instance of slidenavigationcontroller (i named sn1)
  • sn1 has initial uiviewcontroller uvc1
  • log1 calls presentviewcontroller: sn1 making log1 presentingviewcontroller of sn1 (sn1.presentingviewcontroller == log1)
  • uvc1 setup make sn1 have sliding menu menu1
  • menu1 has logout option
  • menu1 create loginviewcontroller log2
  • sn1 present log2 making sn1 presentingviewcontroller of log2
  • after logging in log2, created sn2. thus, log2 presentingviewcontroller of sn2
  • sn2 has own uvc2
  • uvc2 setup make sn2 have sliding menu menu2
  • now here crazy part
  • menu2's memory address same menu1
  • menu2 creates log3
  • again, log2 , log3 has same memory address
  • thus, when sn2 presents log3, error occur since log3 log2 , log2 presentingviewcontroller sn2
  • the rest crash

this method/function creating/attaching menuvc slidenavigationcontroller

-(void)setupslidenavigation:(slidenavigationcontroller *)sn {     menuvc *menuvc = [[menuvc alloc] initwithnibname:@"menuvc" bundle:nil];      uibarbuttonitem *leftitem = [[uibarbuttonitem alloc]                                  initwithimage:[uiimage imagenamed:@"setting_btn_09.png"]                                  style:uibarbuttonitemstyleplain                                  target:nil                                  action:nil];      uiedgeinsets edges = uiedgeinsetsmake(0, -16, 0, 0);     leftitem.imageinsets = edges;      sn.leftmenu = menuvc;     sn.leftbarbuttonitem = leftitem; } 

uvc1 , uvc2 setup one:

-(void)viewwillappear:(bool)animated {     [super viewwillappear:animated];      [[uiutils sharedinstance] setupslidenavigation:(slidenavigationcontroller*)self.navigationcontroller]; } 

also happened when created loginviewcontroller:

[[loginviewcontroller alloc] initwithnibname:@"loginviewcontroller" bundle:nil] //called viewdidload method of menuvc 

this behaviour resulted "application tried present modally active controller"

i used "automatic release" mechanism of ios/objc/compiler


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -