开发者

Restore file document base application

开发者 https://www.devze.com 2023-04-11 17:05 出处:网络
I have a little problem with my first document based application. Is very simple: on myDocument.m I make some method

I have a little problem with my first document based application. Is very simple: on myDocument.m I make some method

- (IBAction)salva:(id)sender {

    [array addObject:@"Hello"];

    [nomeLabel setStringValue:@"ciao"];

    NSLog(@"%@",[array ob开发者_StackOverflow社区jectAtIndex:0]);

}

this for save a value on my array

- (BOOL) writeToURL:(NSURL *)url ofType:(NSString *)typeName error:(NSError **)outError {
    return [array writeToURL:url atomically:YES];
}

this for save the array on a file

- (void) imposta {

    [nomeLabel setStringValue:[array objectAtIndex:0]];

    NSLog(@"Ciao");

}

with this method I set the content of a label with the content of array

- (BOOL) readFromURL:(NSURL *)url ofType:(NSString *)type error:(NSError **)outError{

    [ array release];

    array = [[NSMutableArray alloc] initWithContentsOfURL:url];

    NSLog(@"%@",[array objectAtIndex:0]);

    [self imposta];

    return YES;
}

this for load the file. The problem is that I can't set the label with the content of loaded array. The array wes loaded because with an NSLog I see the correct value, the problem is that I can't put it on th


When opening a document for the first time, -readFromURL:ofType:error: is called before the window controllers are instantiated. That means your nameLabel connection is probably nil. You should update in -awakeFromNib or -windowControllerDidLoadNib: at the very earliest.

But really, NSDocument is a model object and therefore shouldn't be connected directly to a view object anyway. The document should just be storing its data, and the window controller should be responsible for updating the view.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号