• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: setString question...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: setString question...


  • Subject: Re: setString question...
  • From: Ricky Sharp <email@hidden>
  • Date: Mon, 5 Feb 2007 12:57:44 -0600


On Feb 5, 2007, at 12:38 PM, email@hidden 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.


OK, 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:

One 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:email@hidden
Instant Interactive(tm)   http://www.instantinteractive.com

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: setString question...
      • From: "I. Savant" <email@hidden>
    • Re: setString question...
      • From: email@hidden
References: 
 >setString question... (From: email@hidden)

  • Prev by Date: Re: setString question...
  • Next by Date: Re: setString question...
  • Previous by thread: Re: setString question...
  • Next by thread: Re: setString question...
  • Index(es):
    • Date
    • Thread