views:

163

answers:

1

Hi, i have a Quartz Composition with a Cube, and X/Y/Z rotation inputs are published. On Interface Builder i made a QCView and a QCPatchController with the previous Quartz Composition loaded. In QCView the Patch Controller is binded, and the rotation published ports are binded too to three NSSlider, so when i change the value of the NSSlider's then the cube rotates.

All this works fine, but i want to change the rotation values of the cube from the App Delegate on XCode. I tried to change the value of the NSSliders with IBoulets pointing to them, but this change doesnt apply to the cube, like it does when i change the Sliders directly with my mouse.

What should i instanciate and/or how to access and change this Input_Ports.value throught the CQPatchController?

Thank you very much for reading, i really need help!

A: 

It's actually quite simple! The patch controller will accept KVC's setValue:forKeyPath: just fine. (The desired key path will probably look like patch.Input_Ports.value.)

To connect to your patch controller, you'll need to add an outlet to your app delegate. In your app delegate's .h file, add an instance variable IBOutlet NSObjectController* patchController.

IBOutlet doesn't do anything for the compiler, but it signals to Interface Builder that there's an outlet there. Once you've added that line, you'll be able to go back to Interface Builder and control-drag from your app delegate to your patch controller, thus connecting the patchController outlet to the specific instance in your .nib file.

(There is no .h file for QCPatchController, but it's a subclass of NSObjectController, so you can safely declare it as such.)

andyvn22
That's what i tried, but how do i access the patch controller instance, declared in Interface Builder, from XCode's App Delegate code? I know this could be much newbie, but i actually am...Thank you for your answer!
Alberto MQO
Pouf, I've added info on outlets. Try to phrase and title your question next time so it really focuses on the specific part of the problem that you're having trouble with. (This time, maybe "Accessing instances in nib files programmatically" would've been better, since the question wasn't Quartz Composer-specific. Or, if you knew the term, "Adding an IBOutlet".)
andyvn22
Yes, i needed to know if that kind of instanciation was possible, and i aready know that IBoulet mechanism, but XCode doesnt recongnice QCPatchController class, and i dont know what to import. I tried #import <Quartz/Quartz.h> and other known libraries/frameworks with no luck. What's the import neede?
Alberto MQO
Ah! Use `NSObjectController*` instead. (Now an appropriate question title would've been "Header to import for QCPatchController", and pasting the compile errors/warnings would've been very helpful!)
andyvn22
Interface Builder doesn't allow me to Ctrl-Drag from my App Delegate to the QCPatchController instance, even trying with "id" instead of "NSObjectController" for the class type, so i'm yet at the starting point. I'll follow your advice about focusing on the specific part of the problem next time, this was my first post.
Alberto MQO
When the IBOulet is defined as "id", it doesn't appear in the Connections inspector's oulet list (IBuilder -> App Delegate -> Attributes inspector -> Connections -> outlets) I wonder if is there a way to make "id" Outlets visible so they can be connected.
Alberto MQO
Outlets should be visible even if they are of type id. Are you sure you included the `IBOutlet` keyword before `id`? Are you sure your app delegate instance is of the correct class? Have you tried IB's File->Reload all class files menu item?
andyvn22
Ok, now i have an IBOutlet pointing to the QCPatchController. That was the goal of my post, but now with this code line:[control setValue:[NSNumber numberWithInt:(int)90] forKeyPath:@"patch.Y_Rotation.value"];i get the following error on the console:[<NSObject 0x7fff705844a8> valueForUndefinedKey:]: this class is not key value coding-compliant for the key patch.The key path is correct, and i've tried with other number formats like float, also.
Alberto MQO