Define the class of the sender when making an IBAction connection in Xcode 4,2.1

256 views Asked by At

In Xcode 4 or above, it has a handy function allowing us to CTRL + drag an object from the interface to the .h file to quickly connect the object with an event method (assume the Assistant Editor is enabled).

Say we have an UIButton in the interface, and we want to add an IBAction for its "touch up inside", we enable the assistant window and press/hold CTRL + Drag the button to the .h file to quickly generate the necessary codes.

In the popup prompt box, say we set "connection" as "Action".

In the "Type" drop-down, we can select "id" or "UIButton". <--- this is where my problem is.

The strange thing in Xcode 4.2.1 is: no matter what I select, it always generates code: "(id)sender" as the argument.

I know it is easy to manually change it to "(UIButton *) sender", but what is the point of this drop-down when it always generates "(id)"?

Is this is a bug of Xcode or am I missing something to make it directly generate the code "(UIButton *) sender" when I select "UIButton" in this drop-down?

Edited on 27/Feb/2012: This is confirmed solved in Xcode 4.3

1

There are 1 answers

1
Mike K On

- (void)action:(id)sender is just the way actions are defined. you can, in theory, connect different UI elements to the same action. after you've created the connection, you can manually change id to whatever class you want, or just do a cast inside the method.