objective c - How can I set a menu item click to respond to IBAction from another class? -
i'm pretty new xcode/objective-c/cocoa. want implement settings window app.
i have mainmenu.xib
holds main window. menu, want open settings window. created settings.xib
, appropriate .h
, .m
files hold window do.
settings.h:
#import <cocoa/cocoa.h> @interface settings : nswindowcontroller <nsapplicationdelegate> -(ibaction)opensettings:(id)senderid; @property (nonatomic, retain) settings *thiswindow; @end
settings.m:
#import "settings.h" @implementation settings - (void)windowdidload { [super windowdidload]; // implement method handle initialization after window controller's window has been loaded nib file. } // open preferences window - (ibaction)opensettings:(id)senderid { _thiswindow = [[settings alloc] initwithwindownibname:@"settings"]; [_thiswindow showwindow:self]; } @end
i dragged preferences
menu item first responder, , selected opensettings:
there. however, item still disabled , i'm pretty sure it's because did nil link settings
interface mainmenu.xib
, works appdelegate.h/m
.
how create work? other solutions found didn't quite work me.
if understand clear want store mainmenu , mainwindowcontroller in 2 separate classes.
open main menu nib-file. remove window object tree. check in project settings -> general -> main interface still mainmenu (without .xib-extension). create (implement) custom mainwindowcontroller class (with nib-file may be). open appdelegate class. in- (void)applicationdidfinishlaunching:(nsnotification *)anotification
method create instance of main window controller class, show window use code below
mainwindowcontroller *controller=[[mainwindowcontroller alloc] initwithnibname:@"mainwindowcontroller"]; [controller showwindow:nil]; [controller.window makekeyandorderfront:nil];
here is.
objective-c xcode cocoa
No comments:
Post a Comment