• 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: Help with Undo and MVC
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Help with Undo and MVC


  • Subject: Re: Help with Undo and MVC
  • From: David Jeffery <email@hidden>
  • Date: Thu, 6 Nov 2003 08:06:36 -0800

This is not the problem you are currently fighting, but you might also want to fix this before you go any further:

- (NSUndoManager *)undoManager
{
return [self undoManager];
}

...because what you are doing is sending the "undoManager" message to self (over and over and over and...). Your getter method should be like this instead:

- (NSUndoManager *)undoManager
{
return undoManager;
}

David

On Monday, Nov 3, 2003, at 20:24 US/Pacific, Stephen Magyari wrote:

Thank you to Laurent and Drew for the responses, which helped me clarify my
question --

How do I get my model to know that an NSUndoManager exists in my document?
I think I need to either pass the undo manager "down" to the model or have
the model keep a pointer "up" to the document, but I'm lost in either case
in that I can't figure out exactly how to do it in a way that works.

Currently I have in my document's header:
- (NSUndoManager *)undoManager;

and in the implementation:

- (NSUndoManager *)undoManager {
return [self undoManager];
}

Is that correct? If not, how should I do it? If it is correct, then what
should I do differently in the set method below (from my model's
implementation) to get it to recognize "undoManager" (which Xcode says is
undeclared)?

- (void)setBookTitle:(NSString *)title;
{
[[undoManager prepareWithInvocationTarget:self]
setBookTitle:newBookTitle];
[newBookTitle release];
newBookTitle = title;
}

I've tried Drew's suggestion:
[[[doc undoManager] prepareWithInvocationTarget:self]];

But then Xcode says "doc" is undeclared, etc...

I'm clearly missing something or am doing something wrong and need a nudge
(violent shove?) in the right direction. Thank you for the assistance thus
far...

--Stephen


on 11/3/03 12:04 AM, Laurent Daudelin at email@hidden wrote:

on 11/3/03 2:31 AM, Stephen Magyari at email@hidden wrote:

- (void)setBookTitle:(NSString *)title;
{
[[undoManager prepareWithInvocationTarget:self]
setBookTitle:newBookTitle];
[newBookTitle release];
newBookTitle = title;
}

I think the code above is correct (based on the examples I've seen) but my
app won't compile (under Xcode), stating, "error: 'undoManager' undeclared
(first use in this function....)"

Well, I think you should fix the first error you get before trying to get
going with Undo/Redo. Did you declare that 'undoManager' variable? It
doesn't seem like you did in the method above. Is it because it's an
instance variable of the class that implements 'setBookTitle:'?

-Laurent.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Help with Undo and MVC
      • From: Stephen Magyari <email@hidden>
References: 
 >Re: Help with Undo and MVC (From: Stephen Magyari <email@hidden>)

  • Prev by Date: Re: 2 interface questions
  • Next by Date: Alternate row coloring
  • Previous by thread: Re: Help with Undo and MVC
  • Next by thread: Re: Help with Undo and MVC
  • Index(es):
    • Date
    • Thread