NSMatrix - No new NSCells need apply
NSMatrix - No new NSCells need apply
- Subject: NSMatrix - No new NSCells need apply
- From: Lance Drake <email@hidden>
- Date: Sun, 9 May 2004 14:52:23 -0600
The Problem:
------------
Programatically created instances of NSMatrix to not behave as I would
expect. Cells added to an NSMatrix object, already configured with 'n'
rows and 1 column, are not returned by 'cellAtRow:column'
Due Diligence Preport:
----------------------
I have 'RTFM' (repeatedly), visited AppleDev for TechQ&A/SearchResults,
visited and searched CocoaDev/cocoa.mamasan.com, referred to Scott
Anguish(et al) 'Cocoa Programming', referred to Aaron Hillegass 'Cocoa
Programming for MacOSX', read the .h headers and spent HOURS trying all
sorts of different approaches.
The Code:
---------
(Some constants values substituted for simplicity and gosh knows these
code examples in the list always end up getting re-rendered horribly...
so, apologies for any format ugliness... it looked nice when it left
here)
// -----------------------------------------------------------------
NSMatrix* mat = NULL;
NSRect frame = {100,100,200,300};
NSButtonCell* but = [[[NSButton alloc] init] autorelease];
NSSize cellsize = {200, 25};
NSCell* testcell;
[but setButtonType:NSRadioButton];
[but setTitle:@""];
mat = [[NSMatrix alloc] initWithFrame:frame
mode:NSRadioModeMatrix
prototype:but
numberOfRows:13
numberOfColumns:1];
if(NULL != mat)
{
int dex;
int rows;
[mat setCellSize:cellsize];
rows = [mat numberOfRows]; // this WILL == 13...
for(dex = 1; dex <= rows; dex++)
{
NSButtonCell* newbutton = [[[NSButtonCell alloc] init] retain];
[newbutton setButtonType:NSRadioButton];
[newbutton setTitle:(NSString*)num2cfstr(dex)];
testcell = [mat cellAtRow:dex column:1]; // NULL is expected
[mat putCell:newbutton atRow:dex column:1];
testcell = [mat cellAtRow:dex column:1]; // unexpected NULL
}
// -------------------------------------------------------------------
Interesting... The list of radio buttons which appear in the window
(where expected) do function as members of a radio-button group.
NOTE: It does not matter if 'but' is an NSButton, or if the different
'init' routine is called with the 'cellClass' versus 'prototype arg,
or if only 'initwithframe' is call and then 'renewRows' is invoked
afterwards, or if 'addRow' is called or 'insertRows:cells' is used.
NOTHING comes back via 'cellAtRow'.
Letting IB create a stub (2 item) NSMatrix and then adding rows to
THAT does not help. The XCode debugger shows the rows are there in
the NSMatrix. Actually, I don't want to use IB for this chore but
tried it out just to see if it was all ME.
There is no sample code I can find - only messages to other lists
from other people who are having similar problems.
Also - one exciting thing I found was that NSMatrix puts cell #1
at the BOTTOM of the frame and the last cell entered is placed at
the top of the frame. This makes for some excitement if you are
entering an ascending-list as you get a descending-list result.
Should I write up a bug - or am I missing some salient point?
Thanks so much for any consideration or insight you may have to this.
Best Regards,
Lance Drake
_______________________________________________
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.