Undo and Redo still blank


#1

Hi,

I have been working on chapter 9 of the book. I have written the code as it is said in the book until page 145.
Once running, the RaiseMan application doesn’t want to undo or redo anything (blank).

With the debug method

- (BOOL)respondsToSelector:(SEL)aSelector { NSString *methodName = NSStringFromSelector(aSelector); NSLog(@"-DOCUMENT-respondsToSelector: %@", methodName); return [super respondsToSelector:aSelector]; }

I only get these messages :
2012-02-22 16:57:06.901 Chap09_RaiseMan[6698:403] -DOCUMENT-respondsToSelector: windowWillReturnUndoManager:
2012-02-22 16:57:06.902 Chap09_RaiseMan[6698:403] -DOCUMENT-respondsToSelector: undoManagerForWindow:

Thus these two methods are not called :

[code]- (void)insertObject:(Person *)p inEmployeesAtIndex:(NSUInteger)index;

  • (void)removeObjectFromEmployeesAtIndex:(NSUInteger)index;[/code]

In Document.h, I have :

[code]- (void)setEmployees:(NSMutableArray *)a;

  • (void)insertObject:(Person *)p inEmployeesAtIndex:(NSUInteger)index;
  • (void)removeObjectFromEmployeesAtIndex:(NSUInteger)index;[/code]

None of these three methods are called…

In Document.m, I have :

[code]- (void)setEmployees:(NSMutableArray *)a
{
if (a == employees) {
return;
}

[a retain];
[employees release];
employees = a;

}

  • (void)insertObject:(Person *)p inEmployeesAtIndex:(NSUInteger)index
    {
    NSLog(@"-Ajout de %@ à %@", p, employees);

    // Ajouter l’opération inverse dans la pile des annulations
    NSUndoManager *undo = [self undoManager];
    [[undo prepareWithInvocationTarget:self] removeObjectFromEmployeesAtIndex:index];

    if (![undo isUndoing]) {
    [undo setActionName:@“Insérer la personne”];
    }

    // Ajouter la personne dans le tableau
    [employees insertObject:p atIndex:index];
    }

  • (void)removeObjectFromEmployeesAtIndex:(NSUInteger)index
    {
    Person *p = [employees objectAtIndex:index];

    NSLog(@"-Suppression de %@ de %@", p, employees);

    // Ajouter l’opération inverse dans la pile des annulations
    NSUndoManager *undo = [self undoManager];
    [[undo prepareWithInvocationTarget:self] insertObject:p inEmployeesAtIndex:index];

    if (![undo isUndoing]) {
    [undo setActionName:@“Supprimer la personne”];
    }

    [employees removeObjectAtIndex:index];
    }[/code]

My project can be downloaded : http://sangoku888.free.fr/Chap09_RaiseMan.zip

Thanks in advance for the help.


#2

In this example do we have to add an array controller in the Document.xib file ?


#3

In order to solve my problem I have added the array controller :slight_smile:


#4

How do you solve you problem?
I type in the code in page 151 and 152, run the code. But nothing happened to my app.
I use cmd + z, but the undo don’t work. Also, the insertObject: inEmployeesAtIndex is not called.