Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Mac Programming / May 2005



Tip: Looking for answers? Try searching our database.

NSUndomanager

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Manni - 26 May 2005 16:38 GMT
Hi there,

I'm going slightly mad about NSUndomanager. I read Aaron Hillegass'
"Cocoa programming for Mac OS X" several times, but I'm not able to
implement Undo in a single-document Cocoa-App. Aaron just mentions Undo
in Document-Architecure-Apps.

Is there any dirty trick to get undo running in a simple app?

Thanks in advance

Manni
David Phillip Oster - 26 May 2005 17:28 GMT
> I'm going slightly mad about NSUndomanager. I read Aaron Hillegass'
> "Cocoa programming for Mac OS X" several times, but I'm not able to
> implement Undo in a single-document Cocoa-App. Aaron just mentions Undo
> in Document-Architecure-Apps.
>
> Is there any dirty trick to get undo running in a simple app?

How are you getting your undoManager object? Are you sure whatever
method you are using isn't returning nil?

Signature

David Phillip Oster

Manni - 27 May 2005 08:40 GMT
In my class (sublcass of NSObject) I implemented two Methods:

- (IBAction)sort:(id)sender;
- (IBAction)unsort:(id)sender;

In sort I implemented the following:

NSUndoManager *undo = [[NSUndoManager alloc] init];
undo = [self undoManager];
[[undo prepareWithInvocationTarget: self] unsort];
if ( ![ undo isUndoing ] )
[ undo setActionName: @"Unsort" ];
...

In unsort I implemented the following:

NSUndoManager *undo = [self undoManager];
[[undo prepareWithInvocationTarget:self] sort];
if ( ![ undo isUndoing ] )
undo setActionName: @"Sort" ];
...

When calling method sort I get:
*** -[Undo undoManager]: selector not recognized [self = 0x344e20]

Now I'm at a loss ...

Manni
Michael Ash - 27 May 2005 10:39 GMT
> In my class (sublcass of NSObject) I implemented two Methods:
>
[quoted text clipped - 6 lines]
> undo = [self undoManager];
> [[undo prepareWithInvocationTarget: self] unsort];

The selector is unsort:, with a parameter, not unsort. Those are two
completely different things. Try this:

[[undo prepareWithInvocationTarget: self] unsort:sender];
Manni - 27 May 2005 15:31 GMT
Hm, that didn't help much. Still:

*** -[Undo undoManager]: selector not recognized [self = 0x3089c0]

Is there any restriction in a way that not all classes can implement
NSUndpManager? The way I tried it now is exactly how Aaron described it
in his book.
Michael Ash - 27 May 2005 15:54 GMT
> Hm, that didn't help much. Still:
>
[quoted text clipped - 3 lines]
> NSUndpManager? The way I tried it now is exactly how Aaron described it
> in his book.

Ah, I wasn't paying enough attention. My advice is still relevant, but
this error doesn't pertain to it.

The -undoManager method is not magic. You're doing [self undoManager] to
get an undo manager, but in this case self is *your* object, a simple
subclass of NSObject, and you have not written an -undoManager method, so
of course it's failing.

I believe the standard way of doing this in this sort of situation is to
ask your window for the undo manager. So if you're an NSWindowController
subclass, [[self window] undoManager] should get you a suitable undo
manager you can use.
Manni - 27 May 2005 17:57 GMT
I don't get it. :-(

Now I created a completely new project (Document-architecture).

I have a subclass of NSDocument:

@interface UndoClass : NSDocument

My way to call den Undomanager is the followin:

NSUndoManager *undoManager;
undoManager = [self undoManager];
[undoManager registerUndoWithTarget:self
                        selector:@selector(klick:)
                         object:nil];
[undoManager setActionName: @"Yes"];

But ... nothing happens! No error, the program's running fine, but no
undo is possible. It can't be that tricky to get an undomanager to work
...

Yikes!
Manni - 27 May 2005 18:00 GMT
One correction: "object:sender" ... but that doesn't change anything ...
Manni - 27 May 2005 18:59 GMT
Oh no no!! I figured it out: wrong connections in Interface Builder.
:-(

Nevertheless: thanks a lot for your help!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.