• 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
Re: After Unarchive Object Exists, After First GUI Action, gone...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


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


Looks like I found a solution... anyone please let me know if my solution stinks. (or any of the rest of this thing!)
In the method
- (void)windowControllerDidLoadNib:(NSWindowController *) aController
I added this:
[textView setString:[[stickitNotes objectAtIndex:0] noteBody]];






#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


  • Follow-Ups:
    • Re: After Unarchive Object Exists, After First GUI Action, gone...
      • From: Andrew Farmer <email@hidden>
  • Prev by Date: NSScrollView "autoscroll" while adding data?
  • Next by Date: Re: Passing a C String as an argument
  • Previous by thread: After Unarchive Object Exists, After First GUI Action, gone...
  • Next by thread: Re: After Unarchive Object Exists, After First GUI Action, gone...
  • Index(es):
    • Date
    • Thread