NSUndoManager延迟参数评估

时间:2015-04-26 17:38:38

标签: objective-c nsundomanager nsinvocation

我正在尝试使用NSUndoManager的prepareWithInvocationTarget。我想要像

这样的东西

[[self.undoManager prepareWithInvocationTarget:self] doSomethingWithObject:[self.aMutableArray objectAtIndex:0]]

在调用doSomethingWithObject方法之前,不评估undo的参数。换句话说,我不希望参数成为aMutableArray的当前第一个元素,而是aMutableArrayundo的第一个元素。

我应该看一下NSInvocation或NSMethodSignature的特定部分吗?

1 个答案:

答案 0 :(得分:0)

在任何方法调用中,它只是在哪里发生的问题。如果您现在不想评估[self.aMutableArray objectAtIndex:0],请不要将其包含在调用表达式中!相反,将调用表达式调用为该方法将调用[self.aMutableArray objectAtIndex:0]的方法:

[[self.undoManager prepareWithInvocationTarget:self] 
    doSomethingWithObjectAtIndex:0];

...其中doSomethingWithObjectAtIndex:是调用[self.aMutableArray objectAtIndex:0]的位置。