views:

224

answers:

2

Hi

I am a relatively new iPhone app developer so my knowledge is a little sketchy, so please forgive me if this is a bit of a trivial question.

I have a navigation app which drills between table views by calling pushViewController on the navigationController object

I have one particular section which pushes new view controllers sequentially as the user goes through the interface. The view controllers are all subclassed from UIViewController.

It all works fine until it gets to the end, where the idea is the user presses a "Finish" button and is returned to the root view controller (main menu).

So on the button press I call:

[[self navigationController] popToRootViewControllerAnimated:YES];

And it crashes.

I am a bit worried this could be a big problem as this definitly worked at some point but it is now always failing.

Can anyone give any ideas/advice?

A: 

As the others have commented, the first step is to run this is debug mode and figure out where and why you are crashing.

The most common type of crash is using a deallocated object (EXEC_BAD_ACCESS). Have you run the static analyzer? Are you properly retaining your object references?

gerry3
+2  A: 

Some suggestions:

  • Before calling popToRootViewControllerAnimated: confirm that the RootViewController does actually exist. If it died somewhere along the line, calling the method will cause a crash.
  • Check the – viewWillDisappear: and – viewDidDisappear: methods of your last view to make sure you're not doing something dangerous there.
  • Not sure if popping a view causes it to always deallocate but check the dealloc method of the views and their controllers to make sure your not over-releasing something.
  • One mistake I've seen a lot is releasing objects in the data model from controllers. When another controller (in this case the RootViewController) tries to access the data model the app crashes.

It sound's like you need how to use the Xcode debugger. Type in debugger in Xcode help to get pointers.

TechZen