Question

I'm just starting out with obj-c, I'm trying to build an importer to fetch a couple numbers from a piece of formatted text. I started with a wrapping TextField and was able to both get the text into a string and search it as I wanted with

NSString *varImport = [NSString stringWithString:[importTextView stringValue]];

When I switch over to the TextView in the Interface Builder I get there error

-[NSScrollView string]: unrecognized selector sent to instance 0x100429160

I think this may be the root of my problem, although I am dragging over a TextView when I look in the inspector panel its labeled as a ScrollView which I'm not familure with yet.

Through my research I came across two different sites saying that TextView wont directly feed into a string but it was for odd reasons, IE TextView stored the data as a MutableString that was constantly updating and to access it you had to copy the original (Second example) Anyways I'm turning to the experts because I'm clearly doing something wrong and I can't make sense of the answers on the web.

NSString *varImport = [NSString stringWithString:[[import textStorage] string]];

NSString *varImport = [[import string] copy];

Don't worry so much about the other stuff if you don't have the time to explain what's going in the web examples, I mainly want to know about the ScrollView stuff and how to get a string out of it to be able to search it.

Thanks in advance!

Graham

Was it helpful?

Solution

Simply because you are using the wrong method.

NSString *varImport = [NSString stringWithFormat:[importTextView string];

Also, you might have connected the importTextView instance variable to the wrong connection. A NSTextView is always in a NSScrollView. Simply just right-click your object from interface builder and drag the instances to the top of the textview (Where it should show "NSTextView"). Save the nib and try run it again. It should work.

OTHER TIPS

To get text value from a text field or text view you should use - (NSString *)string method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top