Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Treating several controls as an array (...or something)



on 7/31/02 10:05 AM, David Newberry at email@hidden wrote:

> Hello all,
>
> I was curious as to whether or not I could link several controls to one
> Outlet in IB, and then refer to them with by that outlet and an index or
> some other reference. I have four static text fields and four buttons
> (though this number may grow) -- each button is connected to the same
> action, and I was wondering if there was any way to use the sender
> parameter in the action message to get a reference to its accompanying
> field. Brute force would work of course, I'm just looking for something
> more elegant and requiring less conditional code.
>
> Thanks a lot,
> -David Newberry
>

I think an NSMatrix of buttons would work here. In IB, option-drag one of
the button handles so that you get your desired number of buttons. Set the
tag for each individual button so that you can reference each one. Then
connect the NSMatrix to the action method. Inside your action method you can
determine which button was clicked using something like this:

- (IBAction) myAction: (id) sender
{
if ([sender selectedTag] == 0)
{
// First button was clicked
}
}

Eric Wang
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Treating several controls as an array (...or something) (From: David Newberry <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.