views:

42

answers:

1

I've got a bunch of NSTextFields on a window (tagged 1-8) and I'm wondering if it's possible to access each individual text field programatically by its tag number so I can then get/set its value?

I'm a newbie and while I know how to access these fields by name, doing it by tag number will make things an awful lot simpler for what I'm trying to achieve in this particular instance.

Thanks a lot :-)

+3  A: 
the_fourth_textview = [the_superview_containing_all_textfields viewWithTag:4];
KennyTM
Thanks for the quick response, Kenny :-) Unfortunately I'm not up to speed yet on subviews and superviews etc. so I wasn't able to successfully translate the above pseudocode into code that works...I tried: NSTextView *fieldToChange; fieldToChange = [[self superview] viewWithTag:4];but this is obviously wrong. By the way, the window belongs to an NSWindowController subclass within my (NSObject) app if that helps.
Bender
If you don't know which is the superview, just put the window object there.
KennyTM
All fixed now Kenny! Appreciate your help :-)
Bender
unknown: Don't forget to accept this as the correct answer. (Also, NSTextView and NSTextField are different classes.)
Peter Hosey