Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jpefjr

macrumors regular
Original poster
Jul 8, 2008
230
42
Once again I'm stumped and looking for help...I know, I'm just full of stupid newbie questions. :)

I created a toolbar in Interface Builder by dragging the NSToolbar class into my window following the guide here:
http://developer.apple.com/Mac/libr...Conceptual/Toolbars/Articles/ToolbarInIB.html

I added my NSToolbarItem to the toolbar, removed all the other toolbar items, and even added a graphic for my toolbar item. So far so good. Next I followed the guide and added a method to the class in the @interface file (.h) for my view in Xcode.

-(IBAction) startSort;

I know I know, I should have a separate class for my model but for now I lumped everything into the view thinking since this is just a short program and I'm trying to keep it simple to learn. I saved the change to the .h file and according to the guide the next steps are:

2. Select the object representing this class in the Interface Builder document window (it’s often File’s Owner).
3. Right-click (or Control-click) to display the connections window; locate the action method under Received Actions.

OK, I right clicked on all the classes including File's Owner and my custom view and none of them have "startSort" under "Received Actions".

Any help you could provide me on what I'm doing wrong would be most appreciated.

Thanks and have a happy new year,
John Engstrom
 
Is your files owner the same as where you declared the ibaction.

Sorry but I guess I don't know enough to know what you're asking. I declared the ibaction in Xcode, not in Interface Builder. I added the declaration of a instance method that returns an IBAction to the .h file for my view class, SortGrapherView, that inherits from NSView.

OK, I may have gotten a little farther. I clicked on the SortGrapherView object in Interface Builder and clicked on the Actions button for that class in the Library window. I added the action startSort by clicking the "+" and manually typing in "startSort". Then "startSort" showed up under Received Actions when I right-clicked the SortGrapherView object. I dragged the line from the startSort received action to the toolbar item and it seemed to do the right thing.

Then I compiled and ran my program but I couldn't click on the toolbar item because it's greyed out. Any idea how to enable my toolbar item?
 
The action need to take one argument, the sender. Also you don't need to have the return type be an IBAction, just void. Change your method declaration to:

Code:
-(void)startSort:(id)sender;

Make sure it's in the header file and you should be fine.
 
The action need to take one argument, the sender. Also you don't need to have the return type be an IBAction, just void. Change your method declaration to:

Code:
-(void)startSort:(id)sender;

Make sure it's in the header file and you should be fine.

Thank you! That did it! Now on to solve the next problem. :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.