Reputation: 1699
I am subclassing UIViewController to prevent code repetition of my 'masterButtons' and sets of 'subButtons'.
It all appeared to be working beautifully until I realised that after about 1200 page changes - navigating between just 3 blank pages (just the buttons and a few other objects showing) the app will always crash!
Instruments (+ testing on a device) does not show any memory leaks, but does show hundreds of instances of these button objects existing! ('Created & Still Living' filter selected.) Also, viewDidUnload / didReceiveMemoryWarning are never called, from any of the ViewControllers!
I have not had these problems on other pages in my app (where UIViewController is NOT subclassed).
So it appears the ViewController's contents are being re-created, and any previously created are not being deleted. Are there any common pitfalls of subclassing UIViewController that might be causing this? Is there something I could be missing?
Advice would be greatly appreciated. (I feel like throwing my mac out of the window with this problem!)
Top_ViewController (contains 'MasterButtons')
v
Area1_ViewController (subclass of TOP_ViewController) (contains 'subButtons', and a few texts fields etc.)
v
aPage_ViewController (subclass of Area1_ViewController) (currently blank page)
(Using ARC and storyboards. The storyboard View Controllers have a respective 'aPage_ViewController' as their class.)
Upvotes: 0
Views: 90
Reputation: 1326
If you created your storyboard in a loop fashion it might happen that you create new viewControllers
all the time. Each segue transition is creating new viewController
thus there might be no memory leak but your memory will be consumed.
You should be using either UITabBarController
or UINavigationController
to move back and forth and never create loops.
Moreover viewDidUnload
is deprecated in iOS6, perhaps you ignored warning?
EDIT:
Try something like this:
-(void)tab1_IsPressed:(UIButton *)paramSender{
Top_ViewController *target_VC = (Top_ViewController*)[self.storyboard instantiateViewControllerWithIdentifier:@"page_1"];
[self.navigationController popViewControllerAnimated:NO];
[self.navigationController pushViewController:target_VC animated:NO];
}
-(void)tab2_IsPressed:(UIButton *)paramSender{
Top_ViewController *target_VC = (Top_ViewController*)[self.storyboard instantiateViewControllerWithIdentifier:@"page_2"];
[self.navigationController popViewControllerAnimated:NO];
[self.navigationController pushViewController:target_VC animated:NO];
}
Upvotes: 1