Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

BadWolf13

macrumors 6502
Original poster
Dec 17, 2009
271
0
Ok, all I want is a simple TextField, but with multiple lines. I tried the wrapping text field, but it only wraps text, it doesn't accept carriage returns to move editing to the next line. I also tried the Text View, but the text isn't formatted the same way that it does for all the text fields in my app, and it kinda sticks out like a sore thumb. In addition to that, when I test it, and type information into it, then use the -string method to save that entered information, it saves a blank string. Any thoughts or advice?
 
(Assuming you are using a Wrapping Text Field in a nib), I would say you have two options:

You could subclass the field to capture key events, pulling out the CRs (insert them into the string instead of passing to super)

Or use a delegate that responds to -control:textShouldEndEditing:, then determine how the user exited the field using [NSApp currentEvent]. If the event is a key event that is a CR, insert it into the field and return NO (i.e., tell the control not to end editing).
 
(Assuming you are using a Wrapping Text Field in a nib), I would say you have two options:

You could subclass the field to capture key events, pulling out the CRs (insert them into the string instead of passing to super)

Or use a delegate that responds to -control:textShouldEndEditing:, then determine how the user exited the field using [NSApp currentEvent]. If the event is a key event that is a CR, insert it into the field and return NO (i.e., tell the control not to end editing).

Seriously? You can't just do
Code:
txtMyTextBox.MultiLine =true;
? Now, you see, that's where MS does so well...developers developers developers.

;)
 
Thanks Sydde, yes I am using it in a NIB(Actually XIB) file. After subclassing, I can add that into IB, right? I don't like to write the code to create interfaces programmatically.

More importantly, why isn't this included? It seems like an obvious thing that developers will need.
 
I've heard that snakesqzns, but it's not very user friendly. I'm writing this program for public usage, so user-friendly aspects are of key importance.
 
Thanks Sydde, yes I am using it in a NIB(Actually XIB) file. After subclassing, I can add that into IB, right? I don't like to write the code to create interfaces programmatically.

More importantly, why isn't this included? It seems like an obvious thing that developers will need.

Drop the appropriate header file onto the xib list window to make sure the subclass shows up. Then set the subclass in the identity inspector pane of the inspector palette.

Text Fields are not really intended to be used that way. They are meant to contain small amounts of text rather than multiple lines. The delegate or subclass technique is usually sufficient for customizing behavior.
 
I just implemented the delegate technique, and it works great. Thanks for all your help.

One other question I had, when I tried using the NSTextView, I couldn't get the value in the TextView into my program. My understanding was that this

Code:
[thisPart setPartDescription:[description string]];

Should have set the contents of the NSTextView into my PartDescription string, but it didn't. Any ideas about that?
 
I just implemented the delegate technique, and it works great. Thanks for all your help.

One other question I had, when I tried using the NSTextView, I couldn't get the value in the TextView into my program. My understanding was that this

Code:
[thisPart setPartDescription:[description string]];

Should have set the contents of the NSTextView into my PartDescription string, but it didn't. Any ideas about that?

The method you want is probably -stringValue, assuming "description" to be the text field. I would caution against using "description" for an object or variable name, as that is a method name used by every NSObject subclass that conforms to the NSObject Protocol (as does NSObject itself).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.