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

Oats

macrumors regular
Original poster
Jan 8, 2003
194
1
New York
I've read that an NSScrollView contains an NSClipView contains an NSTextView. (At least when you create them with IB, which is what I did.)

I want to get the background color of the NSTextView contained in the NSScrollView, but I don't know how to get the NSTextView reference. Any idea?

[edit: I really want to do this in code, not using Interface Builder.]
 
Last edited:

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
In Interface Builder expand the document hierarchy to show the NSTextField object. If you're in XCode 3 change your document window to tree view (or something like that). In XCode 4 click the disclosure triangle at the bottom of the object bar.
 

Oats

macrumors regular
Original poster
Jan 8, 2003
194
1
New York
I need to know how to reference the NSTextView programmatically. In other words, I want to get the pointer to the NSTextView. For example:
NSTextView* myTextView = [myScrollView documentView];

But the above line of code doesn't work.
 

mfram

Contributor
Jan 23, 2010
1,307
343
San Diego, CA USA
You can get an outlet directly to the text view using IB. Then you don't need to worry about getting it via code. Expand the object in IB and create an outlet connection.
 

Oats

macrumors regular
Original poster
Jan 8, 2003
194
1
New York
I already know how to do this with interface builder. I want to do this in code. I am creating my own subclass of the NSScrollView, and I want to get a reference to the NSTextView it contains within the code.
 

Sydde

macrumors 68030
Aug 17, 2009
2,552
7,050
IOKWARDI
I think it is a mistake to see a NSTextView as a subview of a NSScrollView. NSTextViews are very complicated objects composed of many parts, of which NSScrollView is one. This is true for many AppKit objects, such as NSTableView, or WebKit's WebView. The object you deal with acts as a controller, delivering messages to its parts and mediating interactions between them and with the user.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.