• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
After Unarchive Object Exists, After First GUI Action, gone...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

After Unarchive Object Exists, After First GUI Action, gone...


  • Subject: After Unarchive Object Exists, After First GUI Action, gone...
  • From: John Joyce <email@hidden>
  • Date: Sun, 20 Apr 2008 18:41:58 -0500

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 (email@hidden)

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:
This email sent to email@hidden


  • Prev by Date: Re: Repost: KVO Problem with NSCollectionView
  • Next by Date: Re: horizontal sizeToFit of NSTextView or NSTextField
  • Previous by thread: Re: Cocoa-dev Digest, Vol 5, Issue 648
  • Next by thread: Re: After Unarchive Object Exists, After First GUI Action, gone...
  • Index(es):
    • Date
    • Thread