开发者

objective-c identifying contentView items

开发者 https://www.devze.com 2023-04-01 09:43 出处:网络
Is there a way to identify unique objects within the contentView? For example, I in my mainWin I have a NSView and 2 NSButtons. Using

Is there a way to identify unique objects within the contentView? For example, I in my mainWin I have a NSView and 2 NSButtons. Using

[[mainWin contentView] subviews]; 

I can get all the objects within the mainWin. This works fine for my needs if the object is a subclass of NSView and I've given it a class, for example, in this case I've named the class vHUD and when I log the obj开发者_如何学Pythonect it comes back as

<vHUD: 0x146e10>

This is fine for NSViews I am creating because for the most part if I am making them they are going to serve multiple purposes (content container, being toggled around screen, etc.) and a class should be necessary. I could subclass all the buttons (under NSObject) and go that way, but it seems like a sledgehammer approach if I end up having a lot of buttons. Is there a way I can uniquely identify all of the buttons with something descriptive in IB that can then be retrieved from the object itself? I tried "description" but that didn't return anything.


Have you tried using the tag instance variable in the NSView class?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号