Received Action not showing up

Discussion in 'Mac Programming' started by jpefjr, Dec 31, 2009.

  1. jpefjr macrumors regular

    jpefjr

    Joined:
    Jul 8, 2008
    #1
    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:

    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
     
  2. KoolStar macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
    #2
    Is your files owner the same as where you declared the ibaction.
     
  3. jpefjr thread starter macrumors regular

    jpefjr

    Joined:
    Jul 8, 2008
    #3
    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?
     
  4. JoshDC macrumors regular

    Joined:
    Apr 8, 2009
    #4
    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.
     
  5. jpefjr thread starter macrumors regular

    jpefjr

    Joined:
    Jul 8, 2008
    #5
    Thank you! That did it! Now on to solve the next problem. :)
     

Share This Page