BSD

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • setString question...

    8 answers - 1124 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    Hello,
    I'm brand new to Cocoa, I have been using RealBasic and AppleScript Studio
    for a long time and have finally decided to learn Cocoa.
    K, so I have created a simple little app which has a button which set the
    contents of a NSTextField to a integer, and this works fine. I even
    figured out how to change the color. I just can't seem to figure out how
    to set text in the TextField.
    Here is my code I was trying.
    Thanks,
    tom
    - (IBAction)setTextFieldTo:(id)sender
    {
    // This works
    //[textField setIntValue:2];
    NSString *myText;
    myText = @"Hello World";
    [textField setString: myText];
    [textField setToolTip: @"Hello Tool Tip!"];
    [textField setTextColor: [NSColor greenColor]];
    }
    Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)
    Do not post admin requests or moderator comments to the list.
    Contact the moderators at cocoa-dev-admins(at)lists.apple.com
    Help/Unsubscribe/Update your Subscription:
    %40developershed.com
    This email sent to bsdarchive (AT) developershed (DOT) com
  • No.1 | | 151 bytes | |

    Tom:
    Read the documentation on NSTextField. Just as you set an integer
    value with -setIntValue: you set a string value with -setStringValue:
  • No.2 | | 1715 bytes | |

    I think it's [textField setStringValue:myText] instead of [textField
    setString:myText].

    Hank

    Feb 5, 2007, at 1:38 PM, tjones (AT) acworld (DOT) com wrote:

    Hello,
    I'm brand new to Cocoa, I have been using RealBasic and AppleScript
    Studio
    for a long time and have finally decided to learn Cocoa.

    K, so I have created a simple little app which has a button which
    set the
    contents of a NSTextField to a integer, and this works fine. I even
    figured out how to change the color. I just can't seem to figure
    out how
    to set text in the TextField.

    Here is my code I was trying.

    Thanks,
    tom
    --
    - (IBAction)setTextFieldTo:(id)sender
    {
    // This works
    //[textField setIntValue:2];

    NSString *myText;
    myText = @"Hello World";

    [textField setString: myText];
    [textField setToolTip: @"Hello Tool Tip!"];
    [textField setTextColor: [NSColor greenColor]];
    }

    Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)

    Do not post admin requests or moderator comments to the list.
    Contact the moderators at cocoa-dev-admins(at)lists.apple.com

    Help/Unsubscribe/Update your Subscription:
    %40runbox.com

    This email sent to hankh (AT) runbox (DOT) com

    Hank Heijink
    www.hankheijink.com
    hankh (AT) runbox (DOT) com

    Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)

    Do not post admin requests or moderator comments to the list.
    Contact the moderators at cocoa-dev-admins(at)lists.apple.com

    Help/Unsubscribe/Update your Subscription:
    %40developershed.com

    This email sent to bsdarchive (AT) developershed (DOT) com
  • No.3 | | 1881 bytes | |

    Feb 5, 2007, at 12:38 PM, tjones (AT) acworld (DOT) com wrote:

    I'm brand new to Cocoa, I have been using RealBasic and AppleScript
    Studio
    for a long time and have finally decided to learn Cocoa.

    K, so I have created a simple little app which has a button which
    set the
    contents of a NSTextField to a integer, and this works fine. I even
    figured out how to change the color. I just can't seem to figure
    out how
    to set text in the TextField.

    Here is my code I was trying.

    Thanks,
    tom
    --
    - (IBAction)setTextFieldTo:(id)sender
    {
    // This works
    //[textField setIntValue:2];

    NSString *myText;
    myText = @"Hello World";

    [textField setString: myText];
    [textField setToolTip: @"Hello Tool Tip!"];
    [textField setTextColor: [NSColor greenColor]];
    }

    As I.S. just pointed out, use setStringValue:

    thing I wanted to point out though is that if you had an
    NSTextView instead of NSTextField, then you would be able to use
    setString: (NSTextView inherits from NSText which provides a
    setString:). However, NSTextField does not inherit from NSText.

    Typically, you can get nice compiler warnings about this (e.g.
    'textField may not respond to setString:') My guess is that you
    declared textField as an id (which is a perfectly valid thing to do),
    instead of the more specific type of NSTextField*.

    Ricky A. Sharp mailto:rsharp (AT) instantinteractive (DOT) com
    Instant Interactive(tm)

    Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)

    Do not post admin requests or moderator comments to the list.
    Contact the moderators at cocoa-dev-admins(at)lists.apple.com

    Help/Unsubscribe/Update your Subscription:
    %40developershed.com

    This email sent to bsdarchive (AT) developershed (DOT) com
  • No.4 | | 2617 bytes | |

    Thanks everyone, I had stumbled across the setIntValue in one of the Apple
    Cocoa pdf's, and it was not listed in the Dev Docs for NSTextField but I
    did find it in the NSCell API.

    Thanks again,
    tom

    Mon, February 5, 2007 10:57 am, Ricky Sharp wrote:

    Feb 5, 2007, at 12:38 PM, tjones (AT) acworld (DOT) com wrote:
    >
    >
    >I'm brand new to Cocoa, I have been using RealBasic and AppleScript
    >Studio
    >for a long time and have finally decided to learn Cocoa.
    >>

    >K, so I have created a simple little app which has a button which
    >set the contents of a NSTextField to a integer, and this works fine. I
    >even figured out how to change the color. I just can't seem to figure out
    >how to set text in the TextField.
    >>

    >Here is my code I was trying.
    >>
    >>

    >Thanks,
    >tom
    >>
    >>

    >- (IBAction)setTextFieldTo:(id)sender
    >{
    >// This works
    >//[textField setIntValue:2];
    >>
    >>

    >NSString *myText;
    >myText = @"Hello World";
    >>

    >[textField setString: myText];
    >[textField setToolTip: @"Hello Tool Tip!"];
    >[textField setTextColor: [NSColor greenColor]];
    >}
    >>

    >

    As I.S. just pointed out, use setStringValue:
    --
    thing I wanted to point out though is that if you had an
    NSTextView instead of NSTextField, then you would be able to use
    setString: (NSTextView inherits from NSText which provides a
    setString:). However, NSTextField does not inherit from NSText.
    --
    Typically, you can get nice compiler warnings about this (e.g.
    'textField may not respond to setString:') My guess is that you
    declared textField as an id (which is a perfectly valid thing to do),
    instead of the more specific type of NSTextField*.

    Ricky A. Sharp mailto:rsharp (AT) instantinteractive (DOT) com
    Instant Interactive(tm)
    >
    >
    >


    Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)

    Do not post admin requests or moderator comments to the list.
    Contact the moderators at cocoa-dev-admins(at)lists.apple.com

    Help/Unsubscribe/Update your Subscription:
    %40developershed.com

    This email sent to bsdarchive (AT) developershed (DOT) com
  • No.5 | | 754 bytes | |

    Feb 5, 2007, at 1:57 PM, Ricky Sharp wrote:
    Typically, you can get nice compiler warnings about this (e.g.
    'textField may not respond to setString:') My guess is that you
    declared textField as an id (which is a perfectly valid thing to
    do), instead of the more specific type of NSTextField*.

    A good point. If you've created an outlet for Interface Builder,
    for instance, you may have done this:

    IB id textField;

    Ricky is suggesting you should instead do this:

    IB NSTextField * textField;

    That way, if you send "-setString:" to textField, you'll get a
    compiler warning (that textField may not respond to -setString:)
    since it knows textField is supposed to be an NSTextField.
  • No.6 | | 364 bytes | |

    You should download AppKiDo by Andy Lee. It's quite handy for
    browsing the documentation:

    Pay attention to which version of the documentation you have
    versus the version of AppKiDo you're using. An older version of
    AppKiDo, for example, may not know how to properly display newer
    documentation if its formatting/structure has changed.
  • No.7 | | 485 bytes | |

    Cool, thanks!
    I'll check it out.

    tom

    Mon, February 5, 2007 11:15 am, I. Savant wrote:

    You should download AppKiDo by Andy Lee. It's quite handy for
    browsing the documentation:

    --
    Pay attention to which version of the documentation you have
    versus the version of AppKiDo you're using. An older version of AppKiDo,
    for example, may not know how to properly display newer documentation if
    its formatting/structure has changed.
  • No.8 | | 1908 bytes | |

    Feb 5, 2007, at 2:15 PM, I. Savant wrote:
    You should download AppKiDo by Andy Lee. It's quite handy for
    browsing the documentation:

    Pay attention to which version of the documentation you have
    versus the version of AppKiDo you're using. An older version of
    AppKiDo, for example, may not know how to properly display newer
    documentation if its formatting/structure has changed.

    In fact there's a bug now where it's not detecting every single
    constant (like NSVariableStatusItemLength). Apple must have made
    some tweak to their docs and I didn't notice since AppKiDo was still
    meeting most of my (occasional) needs.

    Lately I've been itching to do some work on it, so maybe I'll get out
    another release some time this century. I'd like to do a major
    overhaul if I can find the time, but I may have to settle for
    incremental point releases. I keep hoping Apple will adopt AppKiDo's
    UI and save me the trouble. But I'd be even happier if they'd
    provide a (public) layer of documentation abstraction so I'm not
    reduced to scraping HTML. I think there's a lot of conceptual ground
    that could be broken in how we approach documentation.

    I think the Cocoa docs are fantastic, a joy to use. To me they are
    an integral part of the Cocoa development experience, just as the
    NextStep docs were. That's why it matters so much to me to be able
    to navigate the docs just the way I want.

    Thanks for the nod, I.!

    Cocoa-dev mailing list (Cocoa-dev (AT) lists (DOT) apple.com)

    Do not post admin requests or moderator comments to the list.
    Contact the moderators at cocoa-dev-admins(at)lists.apple.com

    Help/Unsubscribe/Update your Subscription:
    %40developershed.com

    This email sent to bsdarchive (AT) developershed (DOT) com

Re: setString question...


max 4000 letters.
Your nickname that display:
In order to stop the spam: 6 + 5 =
QUESTION ON "BSD"

EMSDN.COM