objective c - How do I enable the various menu items created by default in a cocoa application? -
i trying make gui simple hex editor have made. can't enable of default menu items (i.e. "open...", "save", etc) no matter grayed out , un clickable.
i have tried link "open..." menu item first responder object's received action opendocument:
making new class name filemenucontroller.m
has 1 method -(ibaction)opendocument:(id)sender;
new xcode, interface builder, , objective-c , @ loss how proceed.
note: not document based application.
thanks help!
you've got right idea. there 2 ways enable menu items, described in enabling menu items. automatic enabling, system check responder chain looking objects implement action each item in menu. if finds responder appropriate action, enables menu item.
so, you've connected menu item first responder, , you've implemented same action in filemenucontroller
class. other things need are:
- make sure
filemenucontroller
inherits nsresponder, can part of responder chain - create instance of
filemenucontroller
, make sure it's part of responder chain.
in truth, don't want separate object manage file menu. instead, you'd put -opendocument:
action in application delegate, since that's part of responder chain , because opening document application (as opposed to, say, window or view). other commands in same menu, save, save as, close, , print implemented not app delegate document, window controller, or whatever object manages document/file. way, open command pretty enabled (since app delegate pretty in responder chain), save, close, , print enabled when there's document available handle commands.
for completeness, other way manage menu item enabling manual way, set enabled/disabled status of each item. don't think want task, though.
Comments
Post a Comment