Re: MultipleNibTabView & check boxes (SOLVED)
Re: MultipleNibTabView & check boxes (SOLVED)
- Subject: Re: MultipleNibTabView & check boxes (SOLVED)
- From: Boyd Collier <email@hidden>
- Date: Fri, 3 Mar 2006 22:12:29 -0800
Tony,
Thanks very much for the reply. Here, in short form, is what I ended
up doing. When I looked at the attributes of one of my check boxes
using the inspector in Interface Builder, I noticed something labeled
"tag." I hadn't remembered reading anything about this and so I
explored what this might be used for. It turns out that I can set
the tag for each check box to whatever I want and then use this to
identify and keep track of check boxes (and other items)
individually. (You and others are probably already well aware of
this.) Then I created a class (called SwitchStateArray), the guts of
which is an array of BOOLs and put an instance of this into the
Window Controller for the window in which the tab views are placed.
Next, in the the File's Owner (of the nib that has the view with the
check boxes) I added the following method that gets called whenever
the user clicks on a check box:
- (IBAction)doCheckStuff:(id)sender {
int t = [sender tag];
if (NSOnState == [sender state])
[[owner ownerSwitchStateArray] setState:YES atIndex:t];
if (NSOffState == [sender state])
[[owner ownerSwitchStateArray] setState:NO atIndex:t]; // [owner
ownerSwitchStateArray] returns a pointer to the array of BOOLs
}
One of the methods of the class SwitchStateArray is setState:
atIndex: So what happens is that the the BOOL at the index
corresponding to the tag I set for a check box in Interface Builder
gets set either to YES or NO, depending on the state of the check
box. The result is that I have an array of BOOLS as a field in the
window controller indicating the state of each check box so that when
the button is clicked to start the process that make use of the
states of the check boxes, all I have to do is read down the array.
(Of course, this assumes that I've been careful in assigning
appropriate values to the tags in Interface Builder.)
Undoubtedly, there are more "cocoa-ish" ways to accomplish my goal,
but the advantage of my method is that I actually understand what's
going on!
My apologies for being rather long-winded and for leaving out some
details. If anyone is wants the details, let me know off the list.
Thanks again,
Boyd
On Mar 2, 2006, at 2:50 PM, Tony Cate wrote:
Boyd,
I assume by notification you mean: click the button, it sends a
'request' notification, and the check box's controller sends one back.
How about keeping a pointer to the (tab) view controller and using
'accessors' to poll the check box states?
Tony
3 Cats And A Mac
http://www.3caam.com
On Mar 2, 2006, at 11:53 AM, Boyd Collier wrote:
I have used the sample code MultipleNibTabView as a starting point
for a project that involves having approximately 10 check boxes in
one of the tab views. Creating the nib for this and loading it
when a particular tab is selected is straightforward, and the
check boxes respond as they should. What I want to be able to do
next is assess the state of each check box when a button on the
window but outside the tab view is hit. Using notifications looks
like one way to keep track of the state of the check boxes, though
perhaps I'm overlooking a more direct approach. If someone has a
suggestion to make, I'd much appreciate hearing it.
Thanks, Boyd
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden