Re: no scroll bars (NSTableView)
Re: no scroll bars (NSTableView)
- Subject: Re: no scroll bars (NSTableView)
- From: Shlok Datye <email@hidden>
- Date: Tue, 9 Jun 2009 21:19:08 +0000
I must have misunderstood your question earlier.
How can I say the app;
look at how many characters the entries have, and then expand the
column-width so that horizontal scroll bars appear,
and the user is able to read whole entries by using the horizontal
scroll bar.
To do this you first need to find the widths of the strings in the
rows using the text attribute being used; and then find the maximum of
those widths and set it to be the column's new width.
Below is a simple method that does this. It assumes that "rowStrings"
is an array of strings that is displayed in the table view. It also
assumes that the table view has only one column. And, of course,
"tableView" refers to the table view.
------------------
- (void)fixColumn
{
NSArray *rowStrings = //something you want
NSTableColumn *tableColumn = [[tableView tableColumns] lastObject];
NSCell *dataCell = [tableColumn dataCell];
NSAttributedString *attrString = [dataCell attributedStringValue];
NSDictionary *attributes = [attrString attributesAtIndex:0
effectiveRange:NULL];
NSMutableArray *widths = [[NSMutableArray alloc] init];
for (NSString *rowString in rowStrings)
{
CGFloat width = [rowString sizeWithAttributes:attributes].width;
[widths addObject:[NSNumber numberWithFloat:width]];
}
CGFloat maxWidth
= [(NSNumber *)[[widths sortedArrayUsingSelector:@selector(compare:)]
lastObject] floatValue];
[widths release];
[tableColumn setWidth:maxWidth];
}
------------------
Then just call this method whenever you need to update the column's
width.
I am sure that this is not the best way of doing this. Plus, if you
have many rows this might not be fast enough. In any case, you should
hopefully be able to adapt this to your needs.
Shlok Datye
Coding Turtle
http://codingturtle.com
On 09.06.2009, at 16:46, Martin Batholdy wrote:
ok,
I think now I can describe my problem with a little more detail;
I have a table view which has only one column.
Now when the user resizes this column expanding it to the right, the
horizontal scroll bar appears and everything is fine.
But I want to size the column, depending on the entries.
So that the user doesn't have to do the resizing manually-
How can I say the app;
look at how many characters the entries have, and then expand the
column-width so that horizontal scroll bars appear,
and the user is able to read whole entries by using the horizontal
scroll bar.
thanks for any hints!
Am 09.06.2009 um 17:38 schrieb Shlok Datye:
I assume you have set your scroll view to automatically hide and
show its scrollbars as needed.
When exactly do the scrollbars not appear but should? Only when the
app first launches? Does the problem remain if you resize the
window slightly (and the scroll view is set to resize with the
window)?
Can you post a sample project that replicates your problem?
Shlok Datye
Coding Turtle
http://codingturtle.com
On 09.06.2009, at 01:57, Martin Batholdy wrote:
hi,
I have set up a NSTableView in the Interface Builder.
I have connected this with a NSObject Outlet.
And I have set the data source of the NSTableView to the NSObject.
The problem I have is that there don't appear any scroll bars even
when the content doesn't fit.
I have a method called "delete" which deletes the selected entry
when a button is pressed.
In this method there is a [TableOutlet reloadData]; call.
After deleting an entry there are appearing at least vertical
scrollbars.
I tried to add the reloadData call to the init call.
I also tried noteNumberOfRowsChanged like suggested in some forum
postings I found ...
But nothing happens.
Can someone help me on this issue?
Thanks!
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden