views:

1973

answers:

2

I'm just starting to learn the iphone API, and I've done plenty of windows programming, and I'm sure there's a way, given the object passed to an event handler, to identify its object id or tag or something.

I created a series of UIButtons in the interface builder, and each has an object ID. But I just can't see where in the iphone API you can get that ID from the UIButton object.

I see everybody going by titleforstate, but that doesn't work for me because they all have the same title. Or do I put an image in the button and use the title as the ID?

The interface builder has an "interface builder identity" which I'm guessing I don't have access to from the iphone API, do I?

There's also a setting called "Tag" in the "view" section of the button attributes, but it's a number. That will do, but I don't see any API call to get that either.

I'm just trying to figure out how to identify a UI control by some means other than it's title. Thanks.

+5  A: 

it's inherited from NSObject, you just need to call for variable.tag

CiNN
marvelous. I looked in every other object that UIButton inherits from except for NSObject. Thanks.
stu
stu, if you approve this as the answer it will help others who have the same question find it.
willc2
And to go along with that is UIView's handy "viewWithTag:" method.
Dave DeLong
+1  A: 

The provided answer works fine for me, but where is it documented? I look at NSObject Protocol Reference and there is no mention of a tag attribute or method.

-(IBAction) buttonPressed:(id)sender {
    int tagNum = [sender tag];

[edit] It turns out that tag is in NSView, not NSObject. Anything that inherits from NSView has a tag attribute.

progrmr