RE: problems filling the NSMatrix with NSImageCells in a NSMutableArray
RE: problems filling the NSMatrix with NSImageCells in a NSMutableArray
- Subject: RE: problems filling the NSMatrix with NSImageCells in a NSMutableArray
- From: Andy Lee <email@hidden>
- Date: Sat, 7 Sep 2002 10:50:31 -0400
At 9:41 AM +0200 9/7/02, Ivan Subotic wrote:
I use the following code:
myMatrix = [[NSMatrix alloc] init];
The documentation says that when I use the addRowWithCells: method on an
empty matrix, that it is going to make a row with enough columns. Am I
misunderstanding something?
I just tried some experiments and apparently you must specify the
exact number of columns when you create the NSMatrix in order for
-addRowWithCells: to work, even if the matrix is starting out empty.
For example:
// NSMatrix *mat = [[NSMatrix alloc] init]; // <-- NO GOOD
NSMatrix *mat =
[[NSMatrix alloc] initWithFrame:NSZeroRect
mode:NSRadioModeMatrix cellClass:[NSTextFieldCell class]
numberOfRows:0 numberOfColumns:7];
int i;
NSMutableArray *arr = [NSMutableArray array];
// Create a row and add it.
for (i = 0; i < 7; i++) // <-- FAILS IF NUMBER IS NOT EXACTLY 7
{
[arr addObject:[[NSTextFieldCell alloc] init]];
}
[mat addRowWithCells:arr];
I got different error messages than you did (maybe because I am
running Jaguar), but the meaning was essentially the same.
Lessons:
* Do not trust docs when the evidence is against them.
* When in doubt, create small code experiments that isolate the
problem to prove the docs are wrong (or not). I keep around a small
scratch project just for quickly testing little bits of code like the
above. There is a tool called F-Script that sounds very good for
this purpose as well, but I haven't tried it.
* When instantiating an NSView class programmatically, check the init
methods for that class and try to choose the best one. It's usually
but not always -initWithFrame:, which is the designated initializer
for most NSViews. Using -init will compile and run just fine, but
this is deceptive because it often causes problems for NSViews with
the default values it uses.
--Andy
_______________________________________________
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.