iphone - is it possible to not dealloc a view controller when the back button is pressed in a navigation controller? -


here issue: have tableview bunch of cells. core data loads task object cells using nsfetchedresultscontroller. right have each cell has detailviewcontroller, stored in dictionary so:

-(void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath{     detailviewcontroller *detailvc;     if (![self.detailviewsdictionary.allkeys containsobject:@(indexpath.row)]){         detailvc = [[detailviewcontroller alloc]initwithnibname:@"detailviewcontroller" bundle:nil];         [self.detailviewsdictionary setobject:detailvc forkey:@(indexpath.row)];     }else{         detailvc = self.detailviewsdictionary[@(indexpath.row)];     }         tasks *task = [[self fetchedresultscontroller] objectatindexpath:indexpath];         detailvc.testtask = task;         [[self navigationcontroller] pushviewcontroller:detailvc animated:yes]; } 

each detailviewcontroller has timer property gets time interval task object correlates cell @ given index path in tableview. here code have detail view controller:

- (void)viewdidload {     [super viewdidload];     [nsthread detachnewthreadselector:@selector(starttimer:) totarget:self withobject:nil]; } -(ibaction)starttimer:(id)sender{ //default value of showbuttonvalue when first loaded 1     if (testtask.showbuttonvalue == 1) {         [startbutton settitle:@"start" forstate:uicontrolstatenormal];         timer = [nstimer scheduledtimerwithtimeinterval:1.0 target:self selector:@selector(timeraction:) userinfo:nil repeats:yes];         testtask.showbuttonvalue = 3;     } else if (testtask.showbuttonvalue == 2) {         [startbutton settitle:@"resume" forstate:uicontrolstatenormal];         [timer invalidate];         timer = nil;         testtask.showbuttonvalue = 3;     } else if (testtask.showbuttonvalue == 3){         [startbutton settitle:@"pause" forstate:uicontrolstatenormal];         timer = [nstimer scheduledtimerwithtimeinterval:1.0 target:self selector:@selector(timeraction:) userinfo:nil repeats:yes];         testtask.showbuttonvalue = 2;     } } -(void)viewwillappear:(bool)animated{     [super viewwillappear:animated];     nametextfield.text = testtask.taskname;     [timerlabel setfont:[uifont fontwithname:@"arial" size:60]];     nsuinteger seconds = (nsuinteger)round(testtask.timeinterval);     nsstring *string = [nsstring stringwithformat:@"%02u:%02u:%02u",                         seconds / 3600, (seconds / 60) % 60, seconds % 60];     timerlabel.text = string;     [[self navigationitem] settitle:[testtask taskname]];      [timerlabel setneedsdisplay];     [self.view setneedsdisplay]; } -(void)viewwilldisappear:(bool)animated{     [super viewwilldisappear:animated];     testtask.taskname = nametextfield.text; } -(void)timeraction:(nstimer *)t {     if(testtask.timeinterval == 0)     {         if (self.timer)         {             [self timerexpired];             [self.timer invalidate];             self.timer = nil;         }     }     else     {         testtask.timeinterval--;     }     nsuinteger seconds = (nsuinteger)round(testtask.timeinterval);     nsstring *string = [nsstring stringwithformat:@"%02u:%02u:%02u",                         seconds / 3600, (seconds / 60) % 60, seconds % 60];     timerlabel.text = string;     nslog(@"%f", testtask.timeinterval); } 

the timer supposed keep on going regardless of whether detail view controller on screen or not. when tap cell first time, go detail view controller , start timer, , go tableview, there no problem , countdown keeps on going. problem if re-tap cell, timer created time decrements 2x fast! not that, string displays remaining time doesn't update upon viewwillappear, updates first time timeraction called.

there bunch of issues, appreciate help!

the code have in didselectrowatindexpath, provided in answer other question (one timer per detail view controller), prevent controller being deallocated when press button. keeping reference detail view controller in dictionary. i'm guessing it's not working because forgot initialize dictionary, it's nil.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -