View Full Version : data between 2 Instantiations
skyhawk
2006.06.19, 02:50 PM
m'k, so I have an NSOpenGLView create in iBuilder and I also have my Controller class, also instantiated via iBuilder.
How would I go about passing data between these 2?
Taxxodium
2006.06.19, 02:55 PM
Add an outlet to the view in your controller. Then control click on the controller (make sure you've instatiated it in IB so that you get a blue cube) and drag a connection to the view. In the inspector window, select the outlet of you just created and click connect.
unknown
2006.06.19, 02:59 PM
You can do it a bit like this:
@implementation MyOpenGLView
- (void)drawGL
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
if(delegate) {
[delegate performSelector:gfxCallback];
}
}
- (void)setDelegate:(id)_delegate graphicsCallback:(SEL)_gfxCallback
{
delegate = _delegate;
gfxCallback = _gfxCallback;
}
@end
@implementation Controller
- (void)awakeFromNib
{
[myOpenGLViewOutlet setDelegate:self graphicsCallback:@selector(glCallback)];
[myOpenGLViewOutlet setNeedsDisplay:YES];
}
- (void)glCallback
{
// Here you can perform any OpenGL commands and they are executed and drawn in the myOpenGLViewOutlet's context
}
@end
Hope that's what you were looking for.
Taxxodium
2006.06.19, 03:16 PM
My solution is far more simple :p
unknown
2006.06.19, 03:18 PM
...but it doesn't do the same thing.
skyhawk
2006.06.19, 03:20 PM
You can do it a bit like this:
@implementation MyOpenGLView
- (void)drawGL
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
if(delegate) {
[delegate performSelector:gfxCallback];
}
}
- (void)setDelegate:(id)_delegate graphicsCallback:(SEL)_gfxCallback
{
delegate = _delegate;
gfxCallback = _gfxCallback;
}
@end
@implementation Controller
- (void)awakeFromNib
{
[myOpenGLViewOutlet setDelegate:self graphicsCallback:@selector(glCallback)];
[myOpenGLViewOutlet setNeedsDisplay:YES];
}
- (void)glCallback
{
// Here you can perform any OpenGL commands and they are executed and drawn in the myOpenGLViewOutlet's context
}
@end
Hope that's what you were looking for.
this does for the most part what I think I want it to do...
though I don't really want to draw any of the opengl commands in my controller class. it's already bloated enough. BUT I SUPPOSE IT WILL WORK :)
PS. "delegate" doesn't exist., what exactly should be there
akb825
2006.06.19, 03:39 PM
You would have to declare a variable. (in this case, id delegate) Personally, if all you want to do is pass information, I would just have functions and make sure that the controller has the instance of the OpenGL view, as per Taxxodium's suggestion. No need for actual code other than the IBOutlet, and a control-click is all you need. You can even just have the controller pass itself to the view through a function so it knows what to do, and not bother with trying to pass selectors back and forth, since you would just know what functions you want to call anyway.
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.