Re: Variables: Why one way and not another?
Re: Variables: Why one way and not another?
- Subject: Re: Variables: Why one way and not another?
- From: Robert Borsuk <email@hidden>
- Date: Sat, 1 Nov 2003 10:34:09 -0500
Okay, let's take this a step further then. In my program I route
everything through the myview.m subclass. What I mean by that is that
I put a button on the window and join to an action contained in the
myview subclass. I set up the following (accessors removed for
simplicity):
//header
@interface myview : NSView
{
IBOutlet id theView;
int myInt;
}
-(IBAction)myButtonPress:(id)sender;
//.m file
#import "myview.h"
@implementation myview
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
[NSApp setDelegate:self];
myInt=0;
}
return self;
}
-(void)awakeFromNib
{
}
- (void)drawRect:(NSRect)rect
{
if (myInt == 0)
{
NSRect r = NSMakeRect(10, 10, 50, 60);
NSBezierPath *bp = [NSBezierPath bezierPathWithRect:r];
NSColor *color = [NSColor blueColor];
[color set];
[bp fill];
}
if (myInt == 1)
{
NSRect r = NSMakeRect(10, 10, 50, 60);
NSBezierPath *bp = [NSBezierPath bezierPathWithRect:r];
NSColor *color = [NSColor redColor];
[color set];
[bp fill];
}
}
-(IBAction)myButtonPress:(id)sender
{
NSBeep();
myInt=1;
[self setNeedsDisplay:YES];
}
Button on the window has myButtonPress as an action. Whenever drawRect
is called the value of myInt is always 0. Window is always open.
Rob
On Nov 1, 2003, at 10:08 AM, Alastair J.Houghton wrote:
On Saturday, November 1, 2003, at 02:35 pm, Robert Borsuk wrote:
I make my Controller by the usual subclass of NSObject, put variables
in the there and every thing is fine.
Like so:
@interface MyController : NSObject
{
int myInt;
}
I write some accessors and life is good. Now I put an NSView on a
window and subclass it. I try the same thing and no go. I notice
that :
@interface myview : NSView
{
int myInt;
}
Doesn't work.
What do you mean by "doesn't work"? What actually happens in your
program? (The above *should* work---it certainly does for views I've
written---so there must be some other problem with your program, and
we'll need to know what the symptoms are before we can help you with
it.)
Kind regards,
Alastair.
_______________________________________________
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.