Frage

i am using below code to add view as addChildViewController.

VideoListVC * videoListVC = [[VideoListVC alloc] initWithNibName:@"VideoListVC" bundle:nil];
UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:videoListVC];
navController.view.frame = self.view_Container.bounds;
videoListVC.view.frame = navController.view.bounds;

[self addChildViewController:navController];
[navController didMoveToParentViewController:self]
[self.view_Container  addSubview:navController.view];

self is MenuVC in which i add multiple ViewControllers as childview. i called MenuVC as pushViewController So when i am in MenuVC i can see VideoListVC as child view. When i called popViewControllerAnimated that time dealloc method not called of MenuVC as well as VideoListVC. So the problem is ViewController memory not release and Apps memory continuously increase due to this. And finally app crash when i surt app around continuously 20 to 25 min.

what is the way to resolved this ?? i had tried removeFromParentViewController but not getting any success.

Any thing is wrong in my code to addChildViewController ??

War es hilfreich?

Lösung

1) Your second line should be

UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:videoListVC];

2) In case you don't use ARC, you should release your VideoListVC and navController at the end, because videoListVC is retained due to the initWithRootViewController call, and navController is retained due to addChildViewController.

3) I don't know if this is important, but Listing 14-1 of Apple's View Controller Programming Guide for iOS shows another sequence when adding a childVC:

 [self addChildViewController:content];                 // 1
 content.view.frame = [self frameForContentController]; // 2
 [self.view addSubview:self.currentClientView];
 [content didMoveToParentViewController:self];          // 3

Hope this helps.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top