Problems calling a method from an IB-created instance...
Problems calling a method from an IB-created instance...
- Subject: Problems calling a method from an IB-created instance...
- From: Jeff Diamond <email@hidden>
- Date: Mon, 05 Oct 2009 14:59:01 -0500
This concept is so fundamental, but I've seen no specific docs about it,
and I haven't succeeded with this after almost 2 years of trying an
reading every tutorial and mail list on the web. As near as I
understand it, what Cocoa calls "outlets" are nothing more than dynamic
instance pointers set by IB that you would use just like a pointer to an
object instance, and that the object instance should contain the
information about what type of object it is. When I try this, I get no
warnings or runtime errors, but nothing happens - I see it make the call
to the View method, but then it just steps right over the call without
entering it. Do I need to cast this to the specific class type or
something?
My goal: Have a control class call instance methods in a View class
created by Interface Builder.
I am currently using XCode 3.1.
What I did:
1) Manually stub out the controller class and the View class files.
2) In IB, drag a blue cube (NSObject) to my nib folder and set it to the
controller class
3) In the controller class file, define the actions and the outlet to
the View object.
4) Connect the Gui objects to the Blue Cube, setting the correct methods
to call from each Gui item < This part works >
5) Connect the Blue Cube to the View, setting its Outlet to the correct
View class (confirmed many times)
6) When implementing the code in the control object, make method calls
to the View class using the Outlet name as a pointer. <This doesn't work>
Any help would be wonderful. If ever I can make this work, I'm gonna
put up an online tutorial that actually explains this.
- Jeff
==============================
I'm not sure how much code is relevant, and I don't want to swamp
anyone. But here's my View class definition:
#import <Cocoa/Cocoa.h>
@interface MyOpenGLView : NSOpenGLView
{
float rotX;
}
// Member functions:
- (void) drawRect: (NSRect) bounds ;
- (void) rotate; // Try to call from control class
- (void) resetGLView; // Try to call from control class
@end
============================
And here is the controller class code:
============================
#import <Cocoa/Cocoa.h>
@interface GuiControl : NSObject
{
// Send info to Gui via outlets
IBOutlet id OpenGLViewOutlet; // My pointer to the IB View instance?
}
// Respond to Gui actions:
-(IBAction)changeRot:(id)sender; // These work.
-(IBAction)resetView:(id)sender;
@end
============================
// ---------- And the controller implementation:
============================
#import "GuiControl.h"
#import "MyOpenGLView.h" // My own View header...
@implementation GuiControl
// Respond to Gui actions:
-(IBAction)changeRot:(id)sender
{
[OpenGLViewOutlet rotate]; // Gets here and silently steps over,
doesn't reach method (no warnings)
}
-(IBAction)resetView:(id)sender
{
[OpenGLViewOutlet resetGLView]; // Gets here and silently steps
over, doesn't reach method
}
@end
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden