I'm having trouble setting the text on a ScintillaView in a
document-based OSX/Cocoa application. I'm using the following code (as a
test) and nothing happens (no text appears in the view):
- (BOOL) readFromData:(NSData *)data ofType:(NSString *)typeName
error:(NSError **)outError
{
BOOL readSuccess = NO;
NSString *fileContents = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
if (fileContents) {
readSuccess = YES;
[mEditor setString:fileContents];
// testing to see if there is contents (there is)
// NSLog("File contents: %@", fileContents);
// testing to see if any text works (it doesn't)
//[mEditor setString:@"Hello world"];
[fileContents release];
}
return readSuccess;
}
I'm brand new to Cocoa and Objective-C so it's entirely likely I'm
missing something really obvious, but no matter what I try, I can't seem
to make any text appear in the ScintillaView (unless I type it manually).
Any pointers would be greatly appreciated.
Cheers,
Matthew Brush
> - (BOOL) readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError
> {
> BOOL readSuccess = NO;
> NSString *fileContents = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
>
> if (fileContents) {
> readSuccess = YES;
> [mEditor setString:fileContents];
> // testing to see if there is contents (there is)
> // NSLog("File contents: %@", fileContents);
> // testing to see if any text works (it doesn't)
> //[mEditor setString:@"Hello world"];
> [fileContents release];
> }
>
> return readSuccess;
> }
>
> I'm brand new to Cocoa and Objective-C so it's entirely likely I'm missing something really obvious, but no matter what I try, I can't seem to make any text appear in the ScintillaView (unless I type it manually).
That should work fine, provided the file contents contains actually something and the editor is not read-only ([ScintillaView setEditable:]).
Mike
--
www.soft-gems.net
Hi,
It turned out that the data/text was OK but the ScintillaView (mEditor)
hadn't been initialized by the time readFromData got called (I was doing
it in awakeFromNib). I was kind of expecting such a programmer error to
blow up in my face like it does with C :)
Thanks for your help (and code).
Cheers,
Matthew Brush
Thanks for the example, it helped. My confusion was with how the
document controller stuff worked and which order the functions got
called in.
Cheers,
Matthew Brush