IBOutlet Problems
IBOutlet Problems
- Subject: IBOutlet Problems
- From: "Shane McAliece" <email@hidden>
- Date: Fri, 4 Feb 2005 12:54:09 +0800
Hi All,
I'm having a few problems getting IBOutlet's to work in the program I am
working on.
The program has a subclass of NSView, as well as a few menu items, an outlet
and an action for each of the menu items. Since the menu action's work, and
the outlet's seem to be working some of the time, I'm pretty sure all the
connections are working alright, but the problem I'm having is that in some
places using the NSMenuItem outlet works, while in others nothing happens.
For example, in the code below, the user selects the Black menu item, and
the action colorBlack successfully runs (I had an NSLog in there originally
and it worked), and it then the action calls the changeColorMenu method
(which also successfully runs).
The problem is however, the [newMenuItem setState..] works (i.e. the
NSMenuItem outlet passed to the method gets a checkmark), but the
[menuFore.. setState...] calls to remove the checkmark do not work (the
checkmark doesn't get removed). I've also tried [menuFore... setTitle:...]
and that doesn't work either.
I have a feeling that since I'm a beginner, I've forgotten something rather
basic that's not letting me access variables in some instances but I can't
for the life of me figure out what it is. Is anybody able to offer any
suggestions or help?
Thanks in advance :)
(Note: the code's been trimmed down an awful lot to just show what's
relevant).
-------- WhiteBoardView.h ----------
#import <Cocoa/Cocoa.h>
@interface WhiteBoardView : NSView {
IBOutlet NSMenuItem *menuForeBlack;
IBOutlet NSMenuItem *menuForeBlue;
IBOutlet WhiteBoardView *whiteBoard;
IBOutlet NSWindow *whiteBoardWindow;
}
- (IBAction)colorBlack:(id)sender;
- (IBAction)colorBlue:(id)sender;
- (void)changeColorMenu:(NSMenuItem *)newMenuItem;
----------------------------------
------- WhiteBoardView.m -------------
#import "WhiteBoardView.h"
@implementation WhiteBoardView
- (void)changeColorMenu:(NSMenuItem *)newMenuItem {
// Disable All Menu Items
[menuForeBlack setState:NSOffState];
[menuForeBlue setState:NSOffState];
// Enable The New Menu Item
[newMenuItem setState:NSOnState];
}
- (IBAction)colorBlack:(id)sender {
[whiteBoard changeColorMenu:menuForeBlack];
}
- (IBAction)colorBlue:(id)sender {
[whiteBoard changeColorMenu:menuForeBlue];
}
@end
---------------------------------------
--
Regards,
Shane McAliece
Email: email@hidden
ICQ: 33537666
MSN: email@hidden
Web: http://shanemca.shorturl.com/
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden