Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kikko088

macrumors member
Original poster
Oct 13, 2010
77
0
Italy
Hi at all, I have a little problem, I create a simple document based project, is very simple.
I habe an action

Code:
- (IBAction)salva:(id)sender {
    [array addObject:@"Hello"];
    [nomeLabel setStringValue:@"ciao"];
    NSLog(@"%@",[array objectAtIndex:0]);
}

that save one value on my array.


This method is for save and load file

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

- (BOOL) readFromURL:(NSURL *)url ofType:(NSString *)type error:(NSError **)outError{
    
    [ array release];
    array = [[NSMutableArray alloc] initWithContentsOfURL:url];
    NSLog(@"%@",[array objectAtIndex:0]);  
    return YES;
}

and this method is for set label with array value.

Code:
- (void) imposta {
    [nomeLabel setStringValue:[array objectAtIndex:0]];
    NSLog(@"Ciao");
}


The problem is that when I load a file the label was not set. The array was loaded correctly ( with NSLog I see the correct value) but I can't set the label with array content.
Where is the error?
 
excuse me, the correct method is

Code:
- (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;
}
 
1. Do you see "Ciao" in the log output? It should be output by the NSLog statement in imposta.

2. Does the "Ciao" in the log output appear after the NSLog(@"%@",[array objectAtIndex:0]); of readFromURL?

3. In imposta, is nomeLabel nil or non-nil? If it's nil, think about what can cause that (e.g. nib not loaded, nib outlet not connected, etc.).
 
the Log on "Imposta" work, the Log on readFromURL... work. The NIB is connected because when when I click on IBAction the label take the correct value.


kikko088
 
1. Post your actual log output.

2. Exactly what is [array objectAtIndex:0]? Is it an actual string, or some other type? What if it's nil? What if it's not an NSString*?

3. What is the string value of nomeLabel before you assign [array objectAtIndex:0] to it? If the two strings are the same, then you won't see a change.

4. Break the problem down into smaller parts. Think about how and where to add other NSLog statements to collect more detailed evidence, such as the before and after string-value of nomeLabel, the actual value and type of the objects in array, etc. Or learn to use the debugger, so you can step through what the code is actually doing.

5. Do a clean build, so there's no question that what's in the files is what's being compiled and rune.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.