CocoaDev

Edit AllPages

How do I get the cells withing a NSMatrix to autoresize like a normal view? I tried just setting the coil thing settings on an NSMatrix, but the cells widths don’t adjust with the window…. use the “autosize cells” option in NSMatrix’s attributes panel

Actually on a related line of thinking, is there a good clean way to get a NSMatrix to adjust the number of rows it has based on the width of the cells and how many will fit. For example, if I have a matrix with 4 cells of fixed width, is there a nice way to automatically set the horizontal spacing to expand as the matrix expands, and when it squishes to an amount of space that will only fit 3 cells, to make a second row with the fourth item? (Imagine “Icon Cell View” like Interface Builder’s instance tab item, although it should work with any kind of cell.. buttons etc.) —-

I realize that this isn’t exactly what you were asking for, but it might get you started on something that leads to success. :-)

I use this class to display a resizable matrix of clickable thumbnail images in a simple image cataloging application. The ThumbnailMatrix lives inside an NSScrollView, which in turn lives in an NSSplitView.

— ThumbnailMatrix.h —

#import <Cocoa/Cocoa.h>

@interface ThumbnailMatrix : NSMatrix

@end

— ThumbnailMatrix.h —

— ThumbnailMatrix.m —

@implementation ThumbnailMatrix

#define COLUMNS 6

@end

— ThumbnailMatrix.m —

In the document that contains the matrix, you can add yourself as an observer for the “thumbnailViewDidEndLiveResize” notification:

[[NSNotificationCenter defaultCenter] addObserver: self 
					 selector: (SEL)@selector(updateViews) 
					     name: @"thumbnailViewDidEndLiveResize" 
					   object: nil];

Then if you want to update any other views in your document after resizing, you can do so in your “updateViews” method.

–Tantle