All I want is a simple multi-line TextField

Discussion in 'Mac Programming' started by BadWolf13, Apr 12, 2010.

  1. BadWolf13 macrumors 6502

    Joined:
    Dec 17, 2009
    #1
    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?
     
  2. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #2
    (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).
     
  3. IBrown macrumors newbie

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

    ;)
     
  4. BadWolf13 thread starter macrumors 6502

    Joined:
    Dec 17, 2009
    #4
    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.
     
  5. snakesqzns macrumors regular

    snakesqzns

    Joined:
    Apr 26, 2007
    #5
  6. BadWolf13 thread starter macrumors 6502

    Joined:
    Dec 17, 2009
    #6
    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.
     
  7. snakesqzns macrumors regular

    snakesqzns

    Joined:
    Apr 26, 2007
    #7
    Sure, so implement the delegate as described in the article I linked.
     
  8. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #8
    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.
     
  9. BadWolf13 thread starter macrumors 6502

    Joined:
    Dec 17, 2009
    #9
    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?
     
  10. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #10
    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).
     

Share This Page