ios - Memory management - How to show an already instantiated ViewController without creating a new instance -
i having major memory management issues. after small use of program crash running out of memory. have found cause, every time create new viewcontroller rather accessing instance, creating new instance.
so app loads , instantiates firstviewcontroller. click button instantiates filterviewcontroller
. here when going firstviewcontroller
creating new instance of follows:
uistoryboard *storyboard = [uistoryboard storyboardwithname :@"mainstoryboard" bundle:nil]; firstviewcontroller *fvc = [storyboard instantiateviewcontrollerwithidentifier:@"firstviewcontroller"]; fvc.modaltransitionstyle = uimodaltransitionstylecoververtical;
and repeat process. way of presenting view controller without re-instantiating it? close submitting app (tomorrow hopefully) need try sorted. thanks!
here presentation of viewcontroller.
[self presentviewcontroller:fvc animated:yes completion:nil];
presenting filterviewcontroller
firstviewcontroller
- (ibaction)searchoptions:(id)sender { filterviewcontroller *ctrl = [[filterviewcontroller alloc] init]; [uiview transitionfromview:self.view toview:ctrl.view duration:1 options:uiviewanimationoptiontransitioncurlup completion:nil]; self.filterviewcontroller = ctrl; [self.navigationcontroller pushviewcontroller:self.filterviewcontroller animated:no]; }
if you're using presentviewcontroller
, previous view calling [self dismissviewcontrolleranimated:yes];
. in method you're creating new controller.
if pushing navigation controller pop navigation controller: [self.navigationcontroller popviewcontrolleranimated:yes];
.
based on last update seems don't have navigation controller , you're adding view subview , storing filter view controller. makes life more complicated , correct way remove setup delegate relationship filter view controller calls first view controller when it's done , first controller transitions views , nil's reference.
if can, change use navigation controller properly. have half code, first view controller seems not in navigation controller. if use nav controller life easy...
Comments
Post a Comment