0

I have a table in my view controller (navigation controller). It contains 5 rows. When I click on one 3rd row, a new view controller is pushed onto the stack. This new controller also contains a table view and the cells in that table view contains text fields (added using cell.contentView addSubView:). On clicking one of the text field, a picker is shown (using textField.inputView) instead of keyboard. Now, without selecting any item in picker, I click on back button, then my view gets popped. But after a while (when I am on my root view controller), the app gets crashed.

But If I click on a text field (which is showing keyboard), and then press back button; no crash occurs. So, what might be the problem??

anshul
  • 846
  • 1
  • 14
  • 32
  • 1
    Can you show some of your code? – Yama Dec 23 '11 at 13:06
  • FirstViewController is My Root Controller and on clicking 3rd cell, SecondViewController gets pushed. When I click on back button on my SecondViewController (picker view showing), then it gets popped, FirstViewController is shown for 2 or 3 seconds and then app gets crashed, Console Log: (while NSZombieEnabled is YES) *** -[SecondViewController respondsToSelector:]: message sent to deallocated instance 0x599d280 – anshul Dec 23 '11 at 13:11
  • 1
    You need to show the code dear. It can't give idea with the console. Also may be null value is passed in some variable and hence the app crashes. – Yama Dec 23 '11 at 13:12
  • @anshul - the log obviously say you should care about memory managment –  Dec 23 '11 at 13:13
  • Turn on zombies: http://stackoverflow.com/questions/5386160/how-to-enable-nszombie-in-xcode . Then run the app, make it crash, and you should get a lot more information out. – mattjgalloway Dec 23 '11 at 13:13
  • Here is what is happening when I run my code with breakpoints on: As soon as I click on back button, ViewWillAppear of FirstViewController gets called (my SecondViewController is popped from the stack); and then the textFieldDelegate methods of my SecondViewController also gets called. It should not be like this. Right???? – anshul Dec 23 '11 at 13:18
  • if you are using Xcode 4.2 or something,u'll find the zombieenable option at : product->edit schema->diagnostics. – Yama Dec 23 '11 at 13:18
  • not getting your point. Do 1 thing,put break points at several points and then debug your app, you will get your problem Also enable zombie as shown. – Yama Dec 23 '11 at 13:20
  • the problem is solved. Has juz written the [textField resignFirstResponder] for all the textFields in the back button action..... happy Coding :) – anshul Dec 23 '11 at 15:12

2 Answers2

0

Looks like you have some bug in your logic. Try to Build and debug and see in debugger(run-debugger) stack of calling functions.

Padavan
  • 1,056
  • 1
  • 11
  • 32
0

If you use a pointer without initializing it to nil or any other object, you are propably going to end up accessing memory which isn't yours. this type of code will also give an EXC_BAD_ACCESS error , that means you are truing to use memory which is not yours. so first trace your code using break points line by line.

kulss
  • 2,057
  • 1
  • 14
  • 16