Reload TextField document-based application

Discussion in 'Mac Programming' started by kikko088, Oct 6, 2011.

  1. kikko088 macrumors member

    Joined:
    Oct 13, 2010
    Location:
    Italy
    #1
    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?
     
  2. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    I don't see where imposta is called anywhere.
     
  3. kikko088 thread starter macrumors member

    Joined:
    Oct 13, 2010
    Location:
    Italy
    #3
    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;
    }
     
  4. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #4
    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.).
     
  5. kikko088 thread starter macrumors member

    Joined:
    Oct 13, 2010
    Location:
    Italy
    #5
    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
     
  6. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #6
    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.
     

Share This Page