Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

thevibesman

macrumors regular
Original poster
Oct 26, 2007
139
0
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

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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

macrumors regular
Original poster
Oct 26, 2007
139
0
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!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.