views:

54

answers:

1

I am having trouble assigning a NSString to the text of a NSScrollView. I have tried the following:

    NSString *medium = codeView.text;

That didn't work so then I tried:

    NSString *medium = [codeView text];

This still doesn't work and it gives me the warning:

NSScrollview may not respond to '-text'

Or in the case of the "." operator it gives me the error:

Request for member 'text' is something not a structure or union.

Does anyone have any advice on how to get around this?

I am initializing the code the following way:

@interface NetCodeViewController : NSObject {
    IBOutlet NSTextView *codeView;
}
@property(nonatomic, retain) id *codeView;
@end
+2  A: 

This:

NSString *medium = codeView.text;

And this:

NSString *medium = [codeView text];

Are actually identical in terms of the generated code (when it works). The difference being that the dot version does additional validation (and then GCC produces an imponderable struct error message anyway).

The real problem is that codeView is declared to be an NSScrollView. You probably want it to be an NSTextView and want to connect it to the NSTextView contained within the scroll view.

bbum
Ok, but then my problem changes then, in Interface Builder it will not connect to my IBOutlet unless it is a NSScrollView. (I am using a "Text View" as interface builder calls it).
thyrgle
bbum
I did `NSTextView`.
thyrgle
If you have an NSTextView pointer in your code then the compiler shouldn't be complaining about `NSScrollView may not respond`. Post more code, please.
bbum
No sorry, the problem is that when I try dragging a connection in Interface Builder to the "Text View" it only works when my IBOutlet type is declared as `NSScrollView`. Otherwise it will not recognize a NSTextField object as a candidate to be selected as a New Referencing Outlet. I'm not in any way referring to the `NSScrollView may not respond to '-text'`
thyrgle
NSTextField, NSTextView, and NSText are three distinct things. IIRC, you want NSTextView (and your ivar should be declared as such) as that is the class that is typically encapsulated in a scrollview.
bbum
The problem is though, if I define the ivar as a NSScrollView the Interface Builder allows me to make a new referencing outlet to it. If the ivar is declared as a NSTextView (as it should be) interface builder will not allow me to make a referencing outlet to it. I'm sorry if I am not explaining this correctly. Its hard to do this in comments.
thyrgle
Nope -- you are explaining it correctly. It just doesn't make sense. :) Sounds like something is hosed in the interface file somehow. Try making the outlet of type `id` as that should tell IB that the outlet can be connected to anything.
bbum
`id` type doesnt work either :(. Maybe my initialization is wrong. I'm used to iPhone programming and even though I can see they are similar, I can see some differences. But maybe, I am initializing the IBOutlets wrong I will up date the code to show how I am initializing them.
thyrgle