Try using

[text2 setStringValue:[NSString stringWithFormat:@"%i", [[textField1 stringValue] length]]];

Using setIntValue on a text field won't set the text field's stringValue to be a string from that int.

Tim


On 20 Jul 2008, at 12:56, Phil Faber wrote:

Still struggling with documentation!

Simple task. I have two text fields (text1 & text2) and all I'm trying to achieve is to put into text2 a number specifying how many characters there are in the text in text1.

I started with:

[text2 setStringValue:[text1 stringValue]];

..just to make sure I was on the right track and it successfully placed a copy of the text1 text into text2. Now all I needed was to change the code to put the character count instead.

I looked at the documentation and under NSString I found:

Getting a String’s Length
        • – length
        • – lengthOfBytesUsingEncoding:
        • – maximumLengthOfBytesUsingEncoding:

So I click on 'length' and was told that this 'Returns the number of Unicode characters in the receiver.' Not sure if that's the same thing as just counting characters but changed my code to:

[text2 setStringValue:[text1 length]];

and got ...'warning: passing argument 1 of 'setStringValue:' makes pointer from integer without a cast'

..so assuming this means I was trying to place a number into a text field, I changed the code to:

[text2 setIntValue:[text1 length]];

It compiled and linked fine but the code didn't put anything into text2!

Where am I going wrong?_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please 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:
http://lists.apple.com/mailman/options/cocoa-dev/cocoa-dev%40timisted.com

This email sent to [EMAIL PROTECTED]

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please 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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to