Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mdeh

macrumors 6502
Original poster
Jan 3, 2009
345
2
Hi All,
I wonder if I could get some feedback for this particular problem I have run into using NSTableview. (forever pushing further into Hillegas!!)

My goal was to simply set up a table of an arbitrary number of columns. (No problem here, used IB etc). ( Lets just say it was 11).

My problem was how to get the columns to be of equal width. After some reading ( well...a lot of reading!! :) ) and some asking on cocoa, the way I came up with was to, in ( the awakeFromNib method) iterate through all the colums setting the maxWidth property of each column.

This works well, unless I minimize the tableview and then, the columns no longer remain equal in width to each other, but the first 2 get disproportionately wider than the rest.


So, my questions are this.

I had expected to set this up in IB, setting some attributes of NSTableView, not expecting to have to do this amount ( admittedly little) coding. Is this the way **real** programmers do it?

From what I can see, each column expects **some** value, as left to itself, some of my columns set their max values to: "(340282306073709652508363335590014353408.000000)"

Lastly, is there an obvious reason as to why the columns get distorted when the entire tableview is "squeezed", for want of a better description.

Thank you as always....
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
My problem was how to get the columns to be of equal width. After some reading ( well...a lot of reading!! :) ) and some asking on cocoa, the way I came up with was to, in ( the awakeFromNib method) iterate through all the colums setting the maxWidth property of each column.
You could just set the column autoresizing behavior, which can be done in IB or in code (see NSTableViewColumnAutoresizingStyle):
colsizing.png

From what I can see, each column expects **some** value, as left to itself, some of my columns set their max values to: "(340282306073709652508363335590014353408.000000)"
Looks like it might be some form of FLT_MAX... I think IB does this since I've seen it before too.

Lastly, is there an obvious reason as to why the columns get distorted when the entire tableview is "squeezed", for want of a better description.
Can you post a screenshot of an example?
 

mdeh

macrumors 6502
Original poster
Jan 3, 2009
345
2
You could just set the column autoresizing behavior, which can be done in IB or in code



Looks like it might be some form of FLT_MAX... I think IB does this since I've seen it before too.

Well, I think I solved this one. NSTableColumn's width is declared as CGFloat type. The maxWidth is defined as
CGFLOAT_MAX
The maximum allowable value for a CGFloat type. For 32-bit code, this value is 3.40282347e+38F. For 64-bit code, it is 1.7976931348623157e+308.

Available in iPhone OS 2.0 and later.

Declared in CABase.h.


Can you post a screenshot of an example?
Sure! no problem!

Here is the setup. An NSTableView. One Class ( AppController) whose outlet is set to the tableview.
In the method awakeFromNib this code, which is variously commented out depending upon what is being tried.


Code:
#define  COLMAXWIDTH 1000
-(void) awakeFromNib
{
	NSArray *a = [ tv tableColumns];
	/* set each column */
	for ( NSTableColumn *tc in a)
		[tc setMaxWidth: COLMAXWIDTH]; 
	/* declare the sizes of the columns */
	
	for ( NSTableColumn *tc in a)
		NSLog(@"Column size: %f", [tc maxWidth]);
}

So, the first experiment is to simply drag in an NSTableView and set the columns to 10.

Here is the screenshot. (cropped to save space)

small view of table.png

with these attributes:

Attributes.png

And this the console.

[Session started at 2009-03-23 18:18:00 -0700.]
2009-03-23 18:18:00.794 NSTable_Experiment[1275:10b] Column size: 1000.000000
2009-03-23 18:18:00.796 NSTable_Experiment[1275:10b] Column size: 1000.000000
2009-03-23 18:18:00.797 NSTable_Experiment[1275:10b] Column size: 340282306073709652508363335590014353408.000000
2009-03-23 18:18:00.797 NSTable_Experiment[1275:10b] Column size: 340282306073709652508363335590014353408.000000
2009-03-23 18:18:00.797 NSTable_Experiment[1275:10b] Column size: 340282306073709652508363335590014353408.000000
2009-03-23 18:18:00.798 NSTable_Experiment[1275:10b] Column size: 340282306073709652508363335590014353408.000000
2009-03-23 18:18:00.798 NSTable_Experiment[1275:10b] Column size: 340282306073709652508363335590014353408.000000
2009-03-23 18:18:00.798 NSTable_Experiment[1275:10b] Column size: 340282306073709652508363335590014353408.000000
2009-03-23 18:18:00.798 NSTable_Experiment[1275:10b] Column size: 340282306073709652508363335590014353408.000000
2009-03-23 18:18:00.799 NSTable_Experiment[1275:10b] Column size: 340282306073709652508363335590014353408.000000

If I set the column widths, say to 750 Max Width, the console shows this ( I wont' show it ...but it does) and the screen shot is ( first expanded..the last columns do show uniform width)
750_maxWidth_expanded.png

and *compressed*
750_compressed.png

So, not sure what to make of this...I was able to get it to be uniform once, but now cannot get back to that, but the same issue happened. As the window was made narrower, at some point the first 1 or 2 columns ( cannot now recall) stopped becoming narrower and the uniform width was compromised.

Thanks for helping.
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
If you click a column in IB you can prevent it from resizing. You also may want to set the minWidth as well.

If you want equal widths all the time, you need to first set it up in IB like this, and then set Uniform.

I'd also suggest reading the different NSTableViewColumnAutoresizingStyle values in the docs so you know what those are doing.
 

mdeh

macrumors 6502
Original poster
Jan 3, 2009
345
2
If you click a column in IB you can prevent it from resizing. You also may want to set the minWidth as well.

If you want equal widths all the time, you need to first set it up in IB like this, and then set Uniform.

I'd also suggest reading the different NSTableViewColumnAutoresizingStyle values in the docs so you know what those are doing.

thanks kainjow....
As I am beginning to suspect, NSTableView is quite a complicated beast! Somehow, just imagined a few clicks here and there in IB and all would be done.
Thanks again for taking the time to give your feedback...much appreciated.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.