• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSTextView & horizontal scrolling SOLVED?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTextView & horizontal scrolling SOLVED?


  • Subject: NSTextView & horizontal scrolling SOLVED?
  • From: Boyd Collier <email@hidden>
  • Date: Thu, 19 Jan 2006 12:38:20 -0800

This is (yet another) update to my question regarding horizontal scrolling.
I looked at the method BiScrollAspect.m in the sample code TextSizingExample and found that the minimum size for the text view is not 0.0 but rather is set as follows:


frame.size = [scrollView contentSize];
	.
	.
	.
[textView setMinSize:frame.size];


So, in my code, shown below, I changed

[textView setMinSize:NSMakeSize(contentSize.width, contentSize.height)]; // my previous change to Apple's code
to
[textView setMinSize:frameRect.size];


Horizontal scrolling works just as it should with this new code, which makes sense.

QUESTION: Is Apple's documentation wrong or at least misleading (actually, I'm sure that at least one person, me, was misled)? If so, is it worth filing a correction, or am I beating a dead horse that everyone but me knows is dead?

Boyd


I tried to implement horizontal scrolling in a document-based application by following the example discussed in Apple's documentation at
http://developer.apple.com/documentation/Cocoa/Conceptual/ TextUILayer/Tasks/TextInScrollView.html#//apple_ref/doc/uid/20000938


Since I had already done some coding, including creating a nib file for the document window, without horizontal scrolling, I made some changes to what I already had so that I could use my already existing instance of NSTextView rather than allocating one, as is done in Apple's sample code. But in my first attempt, the text in my document window didn't scroll horizontally. However, when I changed

[textView setMinSize:NSMakeSize(0.0, contentSize.height)];
to
[textView setMinSize:NSMakeSize(contentSize.width, contentSize.height)];


my text scrolled horizontally.
QUESTION: Is this an error in Apple's documentation, or have I missed something somewhere (I'm new at cocoa, so this has a high probability)?


Thanks in advance to anyone who can give me some hints, criticism, advice, etc.
Boyd


Here is my code for my document, where I override windowControllerDidLoadNib and set up horizontal scrolling, using Apple's sample code:

- (void)windowControllerDidLoadNib:(NSWindowController *) aController {
[super windowControllerDidLoadNib:aController];


	NSRect frameRect;
	NSWindow *theWindow = [(NSView *)textView window];
	frameRect = [(NSView *)textView frame];

NSScrollView *scrollview = [[NSScrollView alloc] initWithFrame: [[theWindow contentView] frame]];
NSSize contentSize = [scrollview contentSize];
[scrollview setBorderType:NSNoBorder];
[scrollview setHasVerticalScroller:YES];
[scrollview setHasHorizontalScroller:YES]; // changed, for horizontal scrolling
[scrollview setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; // should there be parens??
frameRect = NSMakeRect(0,0, contentSize.width, contentSize.height);
[textView setFrame:frameRect];
[[textView enclosingScrollView] setHasHorizontalScroller:YES]; // added for horizontal scrolling

// [textView setMinSize:NSMakeSize(0.0, contentSize.height)]; // Is this an error in Apple's documentation??
[textView setMinSize:NSMakeSize(contentSize.width, contentSize.height)]; // my change to Apple's code


[textView setMaxSize:NSMakeSize(FLT_MAX, FLT_MAX)];
[textView setVerticallyResizable:YES];
[textView setHorizontallyResizable:YES]; // for horizontal scrolling
[textView setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)]; // for horizontal scrolling


[[textView textContainer] setContainerSize:NSMakeSize(FLT_MAX, FLT_MAX)]; // for horizontal scrolling
[[textView textContainer] setWidthTracksTextView:NO]; // for horizontal scrolling

[scrollview setDocumentView:textView];
[theWindow setContentView:scrollview];
[theWindow makeKeyAndOrderFront:nil];
[theWindow makeFirstResponder:textView];

[self updateView]; // my code, not from Apple doc
}


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40sunstroke.sdsu.edu


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >NSTextView & horizontal scrolling - my error or Apple's? (From: Boyd Collier <email@hidden>)

  • Prev by Date: Re: initial column of NSTableView sorted
  • Next by Date: Re: does NSMenuItem setMixedStateImage or setOnStateImage work?
  • Previous by thread: NSTextView & horizontal scrolling - my error or Apple's?
  • Next by thread: Comparing pixels in an image
  • Index(es):
    • Date
    • Thread