Re: Updating text fields in Cocoa.
Re: Updating text fields in Cocoa.
- Subject: Re: Updating text fields in Cocoa.
- From: Daniel Todd Currie <email@hidden>
- Date: Sun, 1 Feb 2004 00:58:36 -0800
It would seem that you are trying to pass the -setStringValue: method a
C string, whereas it requires an NSString. You can probably pass it a
CFStringRef, as it is compatible ("toll-free bridged") with NSString,
thus avoiding your need for many of your objects. This may work for
your purposes:
[showActive setStringValue:CFArrayGetValueAtIndex(pairCFArrayRef, 1)];
For future reference, the '@' character is unnecessary in your code.
An NSString object might be defined as such:
NSString *someString = @"This is a string.";
However, if you were to use this string in a text field, it would be
implemented as such:
[someTextField setStringValue:someString];
The '@' character is only necessary when defining the string.
Hope this helps,
// Daniel Currie
On 2004 Jan 31, at 23:52, 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.