2

I'm currently working on an app that builds a stack of controllers depending on the user.

Basically, I have a UIViewController that has a UIButton leading to another UIView Controller; that has a button leading to another view controller and so on. The view controllers are pushed so that when the user always press the button, I get a stack of multiple view controllers. The views are popped whenever the user wants to go back to the previous view controller.

Everything is working well (push and pop). However, at random instances, the app would crash. I noticed that it happens when there are already a large amount of views pushed, and I suspect that it can be a memory issue.

My question is, other than pushing the view controllers, is there an alternative so that I can avoid stacked views? Could it also be that the crash is not because of the stacked views but because I'm just missing something out? There is no error presented in the logs so I can't find out what's happening and I'm also new to iOS development.

Thank you very much!

Edit 1: There is no error in the logs but when the app crashes, there is this message:

Thread 1: EXC_BAD_ACCESS(code = 1, address = 0xd000000c)

Edit 2: This is how I am pushing the controller:

CustomController *custom = [self.storyboard instantiateViewControllerWithIdentifier:@"Custom"];
[self.navigationController pushViewController:custom animated:YES];

And this is how I popped it when the back button is pressed:

[self.navigationController popViewControllerAnimated:YES];

Edit 3: After enabling zombie objects in the scheme, I started to get this messages after multiple push and pop:

nested push animation can result in corrupted navigation bar Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted. Unbalanced calls to begin/end appearance transitions for

Do those messages say that the problem is actually on pushing the controller with animations? Thanks everyone!

Edit 4: I'll try to revise the question to make it more descriptive This is my setup:

Controller A displays icons that corresponds to different places. You can click on the icon to push Controller B and display details for Location A.

Controller B displays information about Location A, with a button to show Controller A that now displays icons close to location of Location A. Now, you can again click an icon, say for Location B, and display details and so on.

When the user presses the back button, it should display the previous view controller. This is why I used push and pop. Is there a better way to handle this process. Thanks again!

ryan13
  • 23
  • 6
  • Do you use ARC? How do you push UIViewControllers? I have used push, pop and it works well. Tr y turn on `All Exception Breakpoint`, it will inform you where crashes. – nmh May 21 '14 at 03:26
  • Yes. I'm using ARC. I updated the post to show how I am pushing and popping the views. Actually, I'm getting the correct response when I push and pop. However, when I test the app for continuous push and pop, the app crashes. I'll do what you said on the breakpoint and will update asap. Thank you very much for your answer! – ryan13 May 21 '14 at 03:46

3 Answers3

0

My suggestion is: check if Zombie Objects is enabled and use the instrument "Allocations" to see if your application have, in fact, memory issues. With the informations provided by these tools, you can figure out what is happening with your application and work on it. Tell me if you need help.

Good luck!

scollaco
  • 947
  • 8
  • 13
  • Thank you very much! I'll do what you said and update here asap. – ryan13 May 21 '14 at 03:47
  • I updated the post to include the logs that I got after enabling the zombie objects. I'm not quite sure what they mean. Thanks for your time! – ryan13 May 21 '14 at 08:53
0

When push or pop, you should turn off animation. I think this causes crash when animation does not finish.

Push: self.navigationController pushViewController:custom animated:NO];

Pop: [self.navigationController popViewControllerAnimated:NO];

nmh
  • 2,497
  • 1
  • 15
  • 27
  • I updated the post to include logs before the crash happens. I'll try to remove the animations and see if it will remove the errors. Thanks! – ryan13 May 21 '14 at 08:54
-1

My guess is that you push multiple view controllers with animations - this may be a root cause of error. If you push more than one view controller you should animate only LAST push, say:

VC1 *vc1 = [self.storyboard instantiateViewControllerWithIdentifier:@"VC1"];
[self.navigationController pushViewController:vc1 animated:NO];
VC2 *vc2 = [self.storyboard instantiateViewControllerWithIdentifier:@"VC2"];
[self.navigationController pushViewController:vc1 animated:NO];
VC3 *vc3 = [self.storyboard instantiateViewControllerWithIdentifier:@"VC3"];
[self.navigationController pushViewController:vc1 animated:YES];

However, i hardly imagine the situation where the multiple push would be necessary - i think it always leads to bad UX.

Petro Korienev
  • 4,007
  • 6
  • 34
  • 43
  • I updated my post to explain a scenario on why multiple push happens (It's actually not multiple push that happens at the same time. The push only happens when a user presses a button, which will show a view that has another button that when pressed will push another view and so on.) I already tried removing the animation but I still get the crash. – ryan13 May 21 '14 at 09:16
  • Check please question and an answer: http://stackoverflow.com/a/14413252/2392973, you definitely trigger push more than once (you console log says it). Probably you did connect a push segue in storyboard? and then you do push in code? – Petro Korienev May 21 '14 at 09:39
  • Apologies. I just found out that the log I posted regarding the nested push is not related to the random crash that I'm experiencing. (But thanks to the link. It will help me when I address that other issue). So, in the original problem, I'm not sure if the crash is due to the stack of controllers, but when I checked the memory, after multiple push, it shoots up to 400-500MB which is far from my typical 35MB. Could that be the problem? But then, if it is, how will I address the need for nesting view controllers? Thank you very much! – ryan13 May 21 '14 at 10:03