-1

I'm writing a Mac application, and I have a text field whose contents I would like to update. In the Interface Builder I control-dragged my text field into AppDelegate.h, which created the line

@property (unsafe_unretained) IBOutlet NSTextField *cStatus;

Now in my AppDelegate.m I want to edit the status, in the following function:

static void Handle_DeviceMatchingCallback(void *inContext, IOReturn inResult, void *inSender, IOHIDDeviceRef inIOHIDDeviceRef){
   NSLog(@"\nDevice added: %p\nDevice count: %ld", (void*)inIOHIDDeviceRef, USBDeviceCount(inSender));
   [cStatus setString:@"Connected"];
}

but this gives me the error "Use of undeclared variable cStatus". I'm very new to XCode, InterfaceBuilder, and Objective C in general, how do I reference this text field? Thanks.

Nick
  • 6,900
  • 5
  • 45
  • 66

1 Answers1

2

cStatus is a property so try:

[self.cStatus setString:@"Connected"];
Gary
  • 5,642
  • 1
  • 21
  • 41
  • Please post the code from AppDelegate.m, the line you quoted must not be in the @implementation section – Gary Jan 27 '13 at 05:11
  • It is in the implementation section. Actually though, the line I referred to is inside a C-style function (because I'm dealing with USB human interface devices, which involves C code). Could that be related to the issue? – Nick Jan 27 '13 at 05:19
  • 1
    That is your problem, you can't reference self from a function like that. You need to find a mechanism for the C function to call back to your obj-c object. – Gary Jan 27 '13 at 05:23
  • So I can write an objective C function that changes the text view's contents, but I can't call that function from within my C function either. – Nick Jan 27 '13 at 05:31
  • I solved it with a reference to my "self" object, as described in diciu's answer here: http://stackoverflow.com/questions/801976/mixing-c-functions-in-an-objective-c-class – Nick Jan 27 '13 at 05:52