1

Xcode 4.3 will start producing mainmenu.xib

I look at that mainmenu.xib

It has an object named Main Menu

I go and look at what are the menu points too

Menu Item - Show All for example, link to unhideAllApplications:

I try to find where is unhideAllApplications defined but can't find any. The outlet window says that it's linked to the first responder.

It is linked to first responder

I check the class of first responder, I can't find anything either

The file owner of mainmenu.xib, for example, is an object of class NSApplication.

enter image description here

What's the class of First Responder? There is nothing mentioned in the class view

enter image description here

Curiously there are 3 objects in mainmenu.xib and Application and Owner are both of type NSApplication. Go figure

enter image description here

user4951
  • 32,206
  • 53
  • 172
  • 282

1 Answers1

2

First responder is the currently focused UI element. It changes whenever the focus moves.

The next responder is usually that element's parent, the one after is this parent's parent, and so on, ending with window content view, window, application and maybe application's delegate.

Every event is passed down the chain with each responder either handling it or passing to the next responder.

For example, unhideAllApplications is defined in NSApplication. When this action is generated, each of the responders in the current chain will try it until it is eventually handled by the application object. The difference from sending to the application directly is that other objects will have a chance to intercept it.

Cocoa Event-handling Guide

hamstergene
  • 24,039
  • 5
  • 57
  • 72
  • If unhideallaplications is defined in NSApplication why the IBAction outlet points to the first responder rather than file owners? Also why we have 3 items in the XIB. Fileowners, first responder, and Application where all are NSApplication object (presumably the same one). – user4951 May 22 '12 at 09:22
  • @JimThio They are not always the same. In other nibs, file's owner will not be the application. And the first responder constantly changes. – hamstergene May 22 '12 at 09:42
  • Okay before I add another +1 vote, why IBAction outlet for show allApplications are linked to first responder instead of file owner? Usually outlet is connected to first responder right? – user4951 May 22 '12 at 10:52
  • @JimThio There is no “usually” here. Outlets and actions are connected in the way developer needs them to be. Any object can refer to any other one. These three are placeholders for external ones that are not contained in the nib itself. – hamstergene May 22 '12 at 11:59