Re: get the list of controls in a NSView
Re: get the list of controls in a NSView
- Subject: Re: get the list of controls in a NSView
- From: Roland King <email@hidden>
- Date: Fri, 12 Feb 2010 20:48:38 +0800
I don't understand what you mean by 'how to fetch each control into an NSView array'. You can get the subviews of the main view and keep going down finding all views that way recursively calling subviews on each, but it won't really help you as some of the controls make a collection of views up when you instantiate them so you are going to find more than just the top-level views of the controls you instantiated in IB. You really just want to get the objects which you dragged into interface builder. eg you put two buttons and a textfield on a view, you want the two buttons and the textfield. That's why I suggested viewWithTag: method, if you give the text view tag number 1 and the two buttons tags 2 and 3, you can easily find them by calling viewWithTag: with each tag from 1 to 3.
No you can't use the name field in IB, that's why I suggested tags, the only piece of information which carries over from IB when your nib is instantiated is the value of the tag field, everything else is just interface builder internal stuff and you can't query it when the nib has been loaded. tags are generally a bit ugly because you have to, as I said, keep your own mapping that tag '2' means button1 but they do work and there is that function to query for them given a top-level view. So if you are unable to hook individual controls up to outlets and actions in IB, this is about the only reasonable way to do it. It's not that hard really, after the nib loads you just iterate through however many tags you have and when you find the view you use a switch statement to set it to the correct instance variable in your code and then hook up the actions. That said, doing this you really aren't gaining much over just instantiating the objects in code in the first place but I know you want to lay things out in IB, so this method will probably work.
On 12-Feb-2010, at 7:43 PM, Jonathan Chacón wrote:
> Hello,
>
> Thanks for the information about tags identification but I've two questions:
>
> How to fetch each control into a NSView array?
>
> Can I identify a control using value of name field in the identity tab of the inspector in IB?
>
> Saludos desde mi iPhone
> Jonathan Chacón
>
> Consultor de accesibilidad, usabilidad y nuevas tecnologías
>
> Teléfono: 679953948
> E-mail: email@hidden
> Blog: http://programaraciegas.weblog.discapnet.es
> Twitter: http://www.twitter.com/Jonathanchacon
>
>
>
> El 12/02/2010, a las 12:17, Roland King <email@hidden> escribió:
>
>> and as I believe I mentioned before, you can assign a numeric 'tag' to each view and control in interface builder and you can use the viewWithTag: method of UIView to search for a specific view with a specific tag. That's not a way of coding I think people usually use, you have to manage your own tag mapping (unfortunately you can't use a #define type value to tag views) and there are usually better ways to do this. However if assigning a tag in Interface Builder is an accessible operation where you've found making connections not to be, this may be a good way to find the objects you set up in IB and add the connections to them in your code.
>>
>>
>> On 12-Feb-2010, at 5:28 PM, Jonathan Chacón wrote:
>>
>>> Hello
>>>
>>> Thank you. I will try a new way to make connections between Interface builder and xCode
>>>
>>> Regards
>>>
>>> Saludos desde mi iPhone
>>> Jonathan Chacón
>>>
>>> Consultor de accesibilidad, usabilidad y nuevas tecnologías
>>>
>>> Teléfono: 679953948
>>> E-mail: email@hidden
>>> Blog: http://programaraciegas.weblog.discapnet.es
>>> Twitter: http://www.twitter.com/Jonathanchacon
>>>
>>>
>>>
>>> El 12/02/2010, a las 05:18, Graham Cox <email@hidden> escribió:
>>>
>>>>
>>>> On 12/02/2010, at 3:12 PM, Jonathan Chacón wrote:
>>>>
>>>>> is there any method to get the list of controls (buttons, labels, splitters, etc) of a NSView?
>>>>
>>>>
>>>> [NSView subViews]
>>>>
>>>> --Graham
>>>>
>>>>
>>> _______________________________________________
>>>
>>> Cocoa-dev mailing list (email@hidden)
>>>
>>> Please do not post admin requests or moderator comments to the list.
>>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>>
>>> Help/Unsubscribe/Update your Subscription:
>>>
>>> This email sent to email@hidden
>>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden