Reputation: 85
I want to implement view transition without using navigation controller like pushviewController mechanism. So, I created the view hierarchy like below. window is superview and contains three subviews.
[window] - aViewController - bViewController - cViewController
If I want to go back to the aVewiController from cViewController, I simply allocate aViewController again like this: [[aViewController alloc] init]
.
Then, after 4 circulations, I got didReceiveMemoryWarning
and "Program exited with status value:0" messages. Its obviously memory issue but no memory leak. Allocating viewcontroller over and over is a problem. I have no idea how to transit view in this case.
Upvotes: 0
Views: 659
Reputation: 9453
If you want your hierarchy of UIViewControllers to behave as they do in UINavigationController case you should
A) show your new ViewController with this call
//This code should be implemented in viewControllerA
[self presentModalViewController:viewControllerB animated:YES]
B) go back one step by calling
//This code should be implemented in viewControllerA
[self dismissModalViewControllerAnimated:YES]
Notes: The way you would tell viewControllerA that you want to close viewControllerB is by sending a NSNotification. The good thing about this is that if you want to go from viewControllerC to viewControllerA you simply send a notification to viewControlerA to dissmisModalViewController and it will recursively dismiss viewControllerC and viewControllerB for you.
Hope this helps
Upvotes: 1
Reputation: 11838
You will need to make sure you are releasing your object after you add them to their superview. and Make sure that you are removing them from their superview when they are sent off screen....
If you want to reuse the object then you can keep them in a list and try to dequeue them like the table view does. This way you wont have to remake them each time.
If you add them to the subview and never remove them. then you will have multiple views that are no longer used that are still being referenced by their super view. therefore they will still be in memory.
Upvotes: 0
Reputation: 6306
You should allocate them only once and transition between the views itself by hiding/unhiding them:
viewController.view.hidden = YES/NO;
Upvotes: 0