• 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: Updating text fields in Cocoa.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Updating text fields in Cocoa.


  • Subject: Re: Updating text fields in Cocoa.
  • From: amy <email@hidden>
  • Date: Mon, 2 Feb 2004 16:07:40 -0800

As Daniel pointed out earlier, setStringValue is expecting an NSString
value as the parameter. You might try converting your C string to an
NSString using the NSString method stringWithCString with code
something like this:

[showActive setStringValue: [NSString stringWithCString:
FileNameStrPtr]];
[showSerial setStringValue: [NSString stringWithCString: SerialStrPtr]];


This method is described in the NSString class documentation as follows:

stringWithCString:

+ (id)stringWithCString:(const char *)cString

Returns a string containing the characters in cString, which must end
with a 0 character and which may not be NULL. cString should contain
characters in the default C string encoding. If the argument passed to
stringWithCString: is not a zero-terminated C string, the results are
undefined.

On Jan 31, 2004, at 11:52 PM, email@hidden wrote:

> Slowly making progress by trial and error, here is the code, the two
> commented out routines are what doesn't work.
>
>> From Foo.h I have the following.
>
> #import <Cocoa/Cocoa.h>
> #import <CoreFoundation/CoreFoundation.h>
> #import <stdio.h>
>
> @interface Preferences : NSObject
> {
> IBOutlet id _XSKeyEMU;
> IBOutlet id enableKey;
> IBOutlet id enableStart;
> IBOutlet id prefWindow;
> IBOutlet id showActive;
> IBOutlet id showSerial;
> NSUserDefaults *pref;
> CFStringRef appID;
> }
> - (IBAction)apply:(id)sender;
> - (IBAction)prefClose:(id)sender;
> - (void)open;
> - (void)updateWindow;
> - (void)savePrefs;
>
> - (BOOL)windowShouldClose:(id)sender;
>
> @end
>
>> From Foo.m I have this semi functional routine.
>
> static void Dump_DeviceList(void)
> {
> CFArrayRef prefCFArrayRef = CFPreferencesCopyAppValue(kKeyCFStr,
> kAppCFStr);
> CFIndex countDeviceList,index,selected;
>
> if (NULL == prefCFArrayRef)
> return;
>
> countDeviceList = CFArrayGetCount(prefCFArrayRef);
>
> printf("\nThe Device list is:");
> for (index = 0;index < countDeviceList;index++)
> {
> CFArrayRef pairCFArrayRef;
> CFStringRef DevNameCFString;
> char* DevNameStrPtr;
> CFStringRef FileNameCFString;
> char* FileNameStrPtr;
> CFStringRef SerialCFString;
> char* SerialStrPtr;
>
> pairCFArrayRef = CFArrayGetValueAtIndex(prefCFArrayRef,index);
> if (NULL == pairCFArrayRef) break;
>
> DevNameCFString = CFArrayGetValueAtIndex(pairCFArrayRef,0);
> DevNameStrPtr = Copy_CFStringRefToCString(DevNameCFString);
>
> FileNameCFString = CFArrayGetValueAtIndex(pairCFArrayRef,1);
> FileNameStrPtr = Copy_CFStringRefToCString(FileNameCFString);
>
> SerialCFString = CFArrayGetValueAtIndex(pairCFArrayRef,2);
> SerialStrPtr = Copy_CFStringRefToCString(SerialCFString);
>
> printf("\n\t%ld\t\"%s\"\t\"%s\"\t\"%s\""
> ,index,DevNameStrPtr,FileNameStrPtr,SerialStrPtr);
>
> selected = 0; //hard code selected match for now.
> if (index == selected)
> {
> // [showActive setStringValue: @FileNameStrPtr]; //this
> doesn't
> work
> // [showSerial setStringValue: @SerialStrPtr]; //this
> doesn't work
> }
>
> DisposePtr(DevNameStrPtr);
> DisposePtr(FileNameStrPtr);
> DisposePtr(SerialStrPtr);
> }
> CFRelease(prefCFArrayRef);
> return 0;
> }
>
> --------------------------------------------
>
> Anyone have code will work in this location as I have read a lot and
> can't
> figure it out and haven't seen any code that works from any sample
> code I have.
>
> Dale
> _______________________________________________
> cocoa-dev mailing list | email@hidden
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Updating text fields in Cocoa. (From: email@hidden)

  • Prev by Date: Re: constants? strings? what do i wrong?
  • Next by Date: Re: Strange character transformation
  • Previous by thread: Re: Updating text fields in Cocoa.
  • Next by thread: Re: Updating text fields in Cocoa.
  • Index(es):
    • Date
    • Thread