• 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 - my error or Apple's?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSTextView & horizontal scrolling - my error or Apple's?


  • Subject: NSTextView & horizontal scrolling - my error or Apple's?
  • From: Boyd Collier <email@hidden>
  • Date: Tue, 17 Jan 2006 12:26:21 -0800

This is (mostly) a repost of a question that failed to evoke any responses.

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:
This email sent to email@hidden


  • Follow-Ups:
    • NSTextView & horizontal scrolling SOLVED?
      • From: Boyd Collier <email@hidden>
  • Prev by Date: Re: Translucent black window
  • Next by Date: Re: Core Data and multithreading (was Re: [Core Data] Improve save performance ?)
  • Previous by thread: Re: [Solved] Code moved to plugin, undefined symbol
  • Next by thread: NSTextView & horizontal scrolling SOLVED?
  • Index(es):
    • Date
    • Thread