Handle mainmenu action

Discussion in 'Mac Programming' started by i.yalovecky, May 20, 2010.

  1. i.yalovecky macrumors member

    Joined:
    Feb 24, 2010
    #1
    How i can handle "prefernces" mainmenu action? In which controller must handle this event? And who must create preference window? Thanks.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    Any object in the responder chain can handle it. I normally add my app delegate to the responder chain and deal with it there. As to who creates the window: your app somewhere. Where is up to you (I normally create a NSWindowController subclass called PreferencesController)
     
  3. i.yalovecky thread starter macrumors member

    Joined:
    Feb 24, 2010
    #3
    Thanks, i trying to do this^ but then i add ibaction to Applicationcontroller and then right-click on it in IfaceBuilder it doesn`t show this function to me^ also when i drag action line from menu item to this object or to first responder it also show only showWindow action^ but not my showPreferences.
    And the same problem with PreferncesController and his xib. I set file owner to PreferencesController and can't get access to my actions and outlets(.

    And yet one. This project was started by other man. In mainmenu xib showed many contrlloer every of them highlighted by blue-bounded-rect then i draging on them action line from menu item, but my controller - PreferencesController not. Why?
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    I don't think you understand how the responder chain works: go and read the documentation. You don't need to connect it in IB: it sends a message and as long as an instance in the responder chain can handle that it will (in chain order).
     
  5. i.yalovecky thread starter macrumors member

    Joined:
    Feb 24, 2010
    #5
    What i do wrong what after xib and controller class creation, name of controller class didn't appeared in dropdown list named class in Object Identity in Interface Builder?
     
  6. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #6
    I have no idea. You are either not reading what I type or intentionally ignoring it. Either way it's not helping you so stop, read what I've typed and do what I say.

    You do not need to connect anything in Interface Builder. The menu item will send message via the responder chain. If the first responder does not handle it then it gets passed to the next responder and so on. So you simply need to ensure that whatever object you want to handle the message is in the responder chain.

    As I said I use the object that I set as the application delegate for this.

    I suggest you stop writing code/messing around in Interface Builder and read the [http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/EventOverview/EventArchitecture/EventArchitecture.html#//apple_ref/doc/uid/10000060i-CH3-SW2]documentation[/url].
     
  7. i.yalovecky thread starter macrumors member

    Joined:
    Feb 24, 2010
    #7
    Wow, thanks, i read it yesterday)))) I'm already have solved problem with handling menu item, but fir this i in IBuilder add new action for FirstResponder.
    But back to xib and controller, do i really need to use responders chain? isn't it not enough just to connect buttons right to controller methods? And even if i will do it somehow with responder chain problem with not appearing class name in Class combobox will care me. I can set there NSViewController and then link _view to my view, but i want to use other member of my controller class.

    And great thanks man for your answers. England forever!!!
     

Share This Page