Get NSTextView from NSScrollView?

Discussion in 'Mac Programming' started by Oats, Aug 8, 2011.

  1. Oats, Aug 8, 2011
    Last edited: Aug 9, 2011

    Oats macrumors regular

    Joined:
    Jan 8, 2003
    Location:
    New York
    #1
    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.]
     
  2. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    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.
     
  3. Oats thread starter macrumors regular

    Joined:
    Jan 8, 2003
    Location:
    New York
    #3
    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.
     
  4. mfram macrumors 65816

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #4
    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.
     
  5. Oats thread starter macrumors regular

    Joined:
    Jan 8, 2003
    Location:
    New York
    #5
    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.
     
  6. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #6
  7. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #7
    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.
     

Share This Page