Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Cocoa Document Based App Question

Cocoa Document Based App Question
Thread Tools
Senior User
Join Date: Feb 2003
Location: USA
Status: Offline
Reply With Quote
Dec 17, 2006, 07:41 AM
 
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
Reply With Quote
Dec 17, 2006, 01:45 PM
 
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
Reply With Quote
Dec 17, 2006, 02:37 PM
 
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
Reply With Quote
Dec 19, 2006, 07:13 AM
 
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
Reply With Quote
Dec 19, 2006, 11:00 AM
 
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
Reply With Quote
Dec 19, 2006, 02:26 PM
 
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
Reply With Quote
Dec 19, 2006, 02:34 PM
 
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
Reply With Quote
Dec 19, 2006, 03:04 PM
 
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
Reply With Quote
Dec 23, 2006, 03:52 PM
 
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
Reply With Quote
Dec 23, 2006, 04:14 PM
 
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'."
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:42 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2