PDA

View Full Version : Basic N00b Question access UITextField defined in xib in Controller




Mac Me Up
Aug 8, 2008, 10:28 PM
Ok, so I'm a seasoned developer, just not a Cocoa one. I have a UITextField in a view defined in a xib. I've linked the view up with my controller and I can put buttons on there and call actions just fine. How do I access controls like text fields though so I can set and get text? I've tried all sorts of things with no luck...

I've googled it as well but I just can't figure out something that is no doubt really simple?



detz
Aug 8, 2008, 11:21 PM
In you header file for you Delegate.

IBOutlet UILabel *labelName;

Then, *Control* click on the Delegate class in IB and drag a connection from the labelName to the label.

....later


[labelName setText:@"testing"];

Mac Me Up
Aug 9, 2008, 03:46 AM
OK so in my interface I set up:
IBOutlet UITextField *txtName;

Then I control click from my delegate and set txtName to be the outlet for the text field. That all works fine. However when I make a call to:
[txtName setText:@"Testing"];
the text fields stays blank. The code is definitely being called, but on the screen nothing happens. I tried a call to setNeedsDisplay, but that didn't seem to do anything. I must be missing something really simple here?