PDA

View Full Version : [sender name] (legit for NSButton?)




thevibesman
Sep 3, 2008, 11:57 AM
I'm an objective-c/cocoa neophyte, so forgive me if I am approaching this the wrong way.

I'm trying to access the "name" of a NSButton set in the interface builder inspector under Interface Builder Identiy from within the IBAction it attached to the button by calling [sender name].

The reason I need to do this is I want all the buttons on in my interface to use the same IBAction but with passing a different name string depending on which button is pressed. I realize I could write a unique IBAction for each button, but that seems much less elegant.

I know name isn't listed on the NSButton reference, but I figured it must be an inherited property. Is name a legitimate property of NSButton? Is this the write way to query the name set in interface builder?

Thanks for the help with my confusion.



robbieduncan
Sep 3, 2008, 12:04 PM
Inherited from what? None of it's superclasses declare name either. I'd suggest you look at title instead.

But in general this is a bad idea: the title may change but the meaning of the button does not. Using the title is not localisation safe. Instead set the tag of each button in interface builder and use this instead. The tags don't change when you localise the application.

And finally: NSButtons are not available on the iPhone so this should be in Mac Programming, not here.

thevibesman
Sep 3, 2008, 12:25 PM
And finally: NSButtons are not available on the iPhone so this should be in Mac Programming, not here.

My mistake, I meant UIButton while going up the inheritance tree in the manual to NSObject I guess I had that in my head and mistyped in the forum post.

Inherited from what? None of it's superclasses declare name either.

I have no idea where I was claiming it came from, I just assumed since you could set a name in IB, that there must be some way to access that name in code. So if not, what is this name box for:

[oh well, can't seem to connect to my FTP server, so the example screenshot is not available for now]

Is that just a name to help in development or does that box actually set some property?

I'd suggest you look at title instead.

But in general this is a bad idea: the title may change but the meaning of the button does not. Using the title is not localisation safe. Instead set the tag of each button in interface builder and use this instead. The tags don't change when you localise the application.

Yeah, for my idea there are a number of things wrong with using title (starting with not all the buttons have titles). Tags are exactly what I'm looking for.

So I guess I'm curious what that name field is all about in IB, tags are an even more elegant solution that what I was trying with name anyway. Thanks!