2

today I came across a strange problem. I started a really simple project where I just had one View with an UITextField on it. During execution of program I wanted to set the text of that TextField but I figured out that UITextField only was referenced to 0x000000.

Of course before I had correctly connected the Outlet to the TextField as I always do - I have got many experiences in working with Xcode and iOS and did it really often before.

I tried everything from deleting the TextField again, creating a new outlet by the help of interface builder or even deleting every peace of code and doing everything from the very beginning. But nothing did work.

Because I did not understand it I created a new project and although I did everything in the same manner this time it worked. Unhopeflly after many many lines of code I added a second view and now I've got the same problem with this second view.

Does anybody now, what I'm doing wrong?

If you need some kind of code, let me know, but believe me, I really just created a new view, put another TextField on it, created the outlet via Xcode and then pressed run. Then I set a breakpoint in the viewDidLoad method and here you are: TextField only is referenced to nil.

Please help me if you have any ideas.

  • Do you get `nil` for the textfield in `viewDidAppear` also? – Alladinian Oct 16 '12 at 20:29
  • Yes, i just tried it and same result – user1751216 Oct 16 '12 at 20:32
  • Maybe if it helps, I just figured out another strange thing: if I add an second text field, this one is not null referenced. the problem is, that if I type in a text in textfield A (the one with null reference) and another text in textfield B (the one which is not null referenced) the text of text field is saved in the textfieldB.text property. Looks a little bit like not corrected addressed variables – user1751216 Oct 16 '12 at 20:35
  • Do you inspect the variables from Xcode's inspector? If yes try to set a breakpoint and do a `po [self yourTextfield]` in the console, or `NSLog` it (there was a bug in the inspector where variables were offset see also [this answer](http://stackoverflow.com/questions/10963268/float-variables-assigned-value-from-line-above)). – Alladinian Oct 16 '12 at 20:41
  • Hi, thanks again for your answer. But unhopeful it did not change anything. Do you have another idea. I think it might be an Xcode bug – user1751216 Oct 16 '12 at 20:59
  • Hi again. I just made a mistake. The po [self textfield] thing works perfectly. So it just was a mistake of Xcode and everything has bee fine the whole time. (argggg). But how can one fix the Xcode problem? Because writing po every time costs a lot of time – user1751216 Oct 16 '12 at 21:05
  • You can either switch to `GDB` or update your Xcode (the bug is fixed in the current version). I guess you've been really unlucky since this is one of the rare cases where the debugger (or the inspector to be acurate) is actually wrong :P – Alladinian Oct 16 '12 at 21:08
  • Okay I'll try the update and if it works, I will take your answer as an answer for this question here, so that everybody else who might have the same problem will better see the solution – user1751216 Oct 16 '12 at 21:14

0 Answers0