Swati
Swati

Reputation: 2918

Display horizontal grid lines in nstable view using cocoa

hi i am working with NSTableView in my app.

I want to display grid lines depending on the number of rows but it shows many lines even when the number of rows are very less.

Is this a usual behavior?

Or am i doing something wrong? I have checked the horizontal grid lines option from xib.

cannot understand how to achieve this using code.

Upvotes: 2

Views: 1728

Answers (2)

Jacob Gorban
Jacob Gorban

Reputation: 1461

What I found to work best for me so far is the following code. Just fool the original grid drawing code to draw only on populated rows.

Subclass NSTableView, if needed and override drawGridInClipRect:(NSRect)clipRect as following:

- (void)drawGridInClipRect:(NSRect)clipRect
{
    NSRect lastRowRect = [self rectOfRow:[self numberOfRows]-1];
    NSRect myClipRect = NSMakeRect(0, 0, lastRowRect.size.width, NSMaxY(lastRowRect));
    NSRect finalClipRect = NSIntersectionRect(clipRect, myClipRect);
    [super drawGridInClipRect:finalClipRect];
}

Upvotes: 2

Leandro
Leandro

Reputation: 1086

If I understood your issue I may say: "YES". It's expected from the NSTableView to be fulfilled of stripes even when empty if you set it so.

I realize that you want also to manage those lines programmatically. Consider check out this method setGridStyleMask: on the NSTableView Class Reference.

Good luck.

Upvotes: 1

Related Questions