 |
 |
Cocoa Document Based App Question
|
 |
|
 |
|
Senior User
Join Date: Feb 2003
Location: USA
Status:
Offline
|
|
I've been programming in Cocoa/ObjC for a number of years, but have just started on my first document based app. So I am probably missing something very basic, and will dig out my Cocoa books and more than likely find the answer. But I still was hoping for some feedback here. So here goes:
How does one connect document actions to menu items? This particular app has a toolbar and a table in each window. I created a method to delete the currently selected row(s) in my document class, but now need to tie that to a menu item.
I've implemented an app controller for other things like a Preferences panel and custom about panel.
Thanks in advance for any input.
|
|
MacBook 2.0 160/2GB/SuperDrive
Lots of older Macs
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Use the First Responder object in the nib.
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Feb 2003
Location: USA
Status:
Offline
|
|
Thanks Chuck! Got it working fine now.
|
|
MacBook 2.0 160/2GB/SuperDrive
Lots of older Macs
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Dec 2006
Location: Missouri
Status:
Offline
|
|
i have the same problem. i want a menu item to send a message to the top most document. i've added
- (IBAction)foo: (id)sender;
to MyDocument.h, but in MainMenu.nib the first responder does not have that method after i drag the new .h file to it.
i thought about using notifications but then all of the open documents would respond and preform the action, which isn't what i want, i just want the top document.
i'm implementing an optional export as xml, but currently the only way i can get it to work is if there is an "export" button on the document, which frankly, looks like crap. i'd like to offer "file>export" from the menu but can't figure this out.
thanks for any help!
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
I already answered this question when techtrucker asked.
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Dec 2006
Location: Missouri
Status:
Offline
|
|
I read your response to techtrucker however your solution did not work for me. as i mentioned my method in MyDocument was not available to connect in IB using first responder. i was cntrl+dragging from my menu item to first responder and didn't see it. i saw many other generic methods ("save", "save as"... etc.) but not "exportAsPlist" that i created.
i did come up with a solution, using an app controler i connected the menu item to an app controller method "export", which then called
[[[NSDocumentController sharedDocumentController] currentDocument] exportAsPlist];
this works, however it doesn't seem like it's the way i should be doing it. am i missing something obvious?
thank you for taking the time to read this
|
|
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Ah, I see. Sorry, I misunderstood. You can add methods to First Responder in the Classes tab. Just double-click First Responder and click Add in the actions inspector.
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Dec 2006
Location: Missouri
Status:
Offline
|
|
awesome! thats what i needed. that worked after i changed my method back to being (IBAction)
instead of the (void) that i had to change it to in order for my sharedController hack to work.
thanks for the help.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Feb 2003
Location: USA
Status:
Offline
|
|
Ok, next question if I may? Referring back to my original post, I added the action to First Responder and the menu item now performs the same function as the toolbar item. Now I need to enable/disable the menu item. Not finding an obvious solution I find myself wanting to use a notification, but wondered if anyone else (Chuck?) had a better idea? Thanks in advance!
|
|
MacBook 2.0 160/2GB/SuperDrive
Lots of older Macs
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
Implement validateMenuItem: in whatever class it is that's supposed to respond to the menu item.
|
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|