I apologize for the beginner nature of this, I must be missing something obvious, but I cannot see it. Archiving works fine. The data is there. I've inserted NSLogs everywhere to no avail. When the file is opened (unarchived) the log showed me the first object in my array has the correct data. But the data for the first object in the array (all are NSStrings) never appears in the textView. Something is erasing or emptying the contents of this string somewhere between unarchiving and display. The other array objects are unaffected.
Here's my implementation file (most of it)
Please help me see what's wrong here...


#import "MyDocument.h"

@implementation MyDocument

- (id)init
{
    self = [super init];
    if (self) {
                stickitNotes = [[NSMutableArray alloc] init];
                StickitNote *aNote = [[StickitNote alloc] init];
                [stickitNotes insertObject:aNote atIndex:0];
                currentNoteIndex = [stickitNotes indexOfObject:aNote];
    }
    return self;
}

- (NSString *)windowNibName
{
    return @"MyDocument";
}

- (void)windowControllerDidLoadNib:(NSWindowController *) aController
{
    [super windowControllerDidLoadNib:aController];
// Add any code here that needs to be executed once the windowController has loaded the document's window.
}

- (NSData *)dataRepresentationOfType:(NSString *)aType
{
        return [NSKeyedArchiver archivedDataWithRootObject:stickitNotes];
}

- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
{
        NSMutableArray *newArray;
        newArray = [NSKeyedUnarchiver unarchiveObjectWithData:data];
        
        if (newArray == nil) {
[textView setString:[[stickitNotes objectAtIndex:currentNoteIndex] noteBody]];
                [textView setNeedsDisplay:YES];
                return NO;
        } else {
                [self setStickitNotes:newArray];
[textView setString:[[stickitNotes objectAtIndex:currentNoteIndex] noteBody]];
                [textView setNeedsDisplay:YES];
                return YES;
        }
}

- (void)newNote:(id)sender
{
        
[[stickitNotes objectAtIndex:currentNoteIndex] setNoteBody:[textView string]];
        StickitNote *aNote = [[StickitNote alloc] init];
        [stickitNotes insertObject:aNote atIndex:[stickitNotes count]];
        currentNoteIndex = [stickitNotes indexOfObject:aNote];
        /* set textView to display current note */
[textView setString:[[stickitNotes objectAtIndex:currentNoteIndex] noteBody]];
        [textView setNeedsDisplay:YES];
}

- (void)nextNote:(id)sender
{
        unsigned int nextNote;
        if (currentNoteIndex == ([stickitNotes count] - 1)) {
                nextNote = 0;
        } else {
                nextNote = currentNoteIndex + 1;
        }
        
[[stickitNotes objectAtIndex:currentNoteIndex] setNoteBody:[textView string]];
        
        currentNoteIndex = nextNote;
[textView setString:[[stickitNotes objectAtIndex:currentNoteIndex] noteBody]];
        [textView setNeedsDisplay:YES];
}

- (void)previousNote:(id)sender
{
        unsigned int prevNote;
        if (currentNoteIndex == 0) {
                prevNote = ([stickitNotes count] - 1);
        } else {
                prevNote = currentNoteIndex - 1;
        }
[[stickitNotes objectAtIndex:currentNoteIndex] setNoteBody:[textView string]];
        currentNoteIndex = prevNote;
[textView setString:[[stickitNotes objectAtIndex:currentNoteIndex] noteBody]];
        [textView setNeedsDisplay:YES];
}

- (void)setStickitNotes:(NSMutableArray *)array
{
        if (array == stickitNotes)
                return; //skips if it is same data?
        [stickitNotes release];

        [array retain];

        stickitNotes = array;

        [textView setString:[stickitNotes objectAtIndex:0]];
}

@end

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to