Re: Button cell state: outlet works, cellWithTag: doesn't
Re: Button cell state: outlet works, cellWithTag: doesn't
- Subject: Re: Button cell state: outlet works, cellWithTag: doesn't
- From: Fritz Anderson <email@hidden>
- Date: Sat, 14 Jun 2003 16:23:31 -0500
On Saturday, June 14, 2003, at 09:34 AM, Jonathan Jackel wrote:
>
I've actually solved this problem, but I don't know why I had a
>
problem in the first place.
>
>
I'm trying to control the state of an on/off button cell in a matrix.
>
The user can turn it on or off explicitly by clicking on it. When
>
certain other things happen, I want the button cell to be turned off
>
by my app.
>
>
If I refer to the cell by its tag, i.e. [theMatrix cellWithTag:23], it
>
always reports that its state is 0, or off, even when it is on.
>
Calling setState: on this cell has no effect. I checked the tag
>
number about 100 times, and other parts of the program that depend on
>
referring to the cell by its tag number work correctly.
>
>
If I instead set up an outlet to an NSButtonCell, and connect that
>
outlet to the cell I am interested in, it all works as expected. The
>
cell reports that its state is on or off as appropriate, and I can
>
change the state by calling setState:.
>
>
Is there a reasonable explanation for this? Why would an outlet work
>
when cellWithTag doesn't?
I tried this out by building a matrix of checkboxes and hooking up a
button to the following action proc:
- (IBAction) toggleThree: (id) sender
{
NSCell * theCell = [mMatrix cellWithTag: 3];
NSAssert(theCell != nil, @"Can't find cell 3!");
int oldState = [theCell state];
if (oldState == NSOnState)
[theCell setState: NSOffState];
else
[theCell setState: NSOnState];
}
It worked, first try.
My guess is that the cells in your matrix didn't have the tags you
thought they did. If there is no cell #23 in your matrix. [theMatrix
cellWithTag: 23] will always return nil, and [nil state] will always
return 0, or NSOffState. This is what you were seeing, and you don't
report having verified that cellWithTag: returned an actual cell
pointer.
-- F
_______________________________________________
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.