I have problem to implement undo and redo in my core data cocoa application. This is second question that I am asking on same topic, (you can read my first question here) and even that I get solid advice on my first question, I still can't make undo and redo to work.
Anyway...here is my current code:
Here is the relevant code from MainWindowController.h file:
#import <Cocoa/Cocoa.h>
#import "AppDelegate.h"
@property (nonatomic,strong) NSManagedObjectContext *mObjContext;
@property AppDelegate *appDelegate;
Here is the code from the MainWindowController.m file:
#import "MainWindowController.h"
@interface MainWindowController () <NSWindowDelegate>
@end
@implementation MainWindowController
- (void)windowDidLoad {
self.appDelegate = (AppDelegate*)[[NSApplication sharedApplication] delegate];
self.mObjContext = self.appDelegate.managedObjectContext;
[[self window]setDelegate:self];
[self windowWillReturnUndoManager:self.window];
}
- (NSUndoManager *)windowWillReturnUndoManager:(NSWindow *)window
{
return [[self document] undoManager];
}
@end
My window has the following Outlets in connection inspector: delegate: File's owner
Menu: MainMenu
Whenever I make changes in the records in my nstableviews, changes are recorded but undo and redo menu items remain gray. I placed break point in windowWillReturnUndoManager, but I can't see any undoManager returned there...Can anyone tell me what I am doing wrong?
Well, the issue is finally solved. I add new edit menu item, while keeping the old one. When I make change in the record, the new menu item had undo item available and worked. Redo worked too.
So I delete the old edit menu item, and now everything works like a charm. Too bad that I didn't try this earlier, but....