相关疑难解决方法(0)

NSInvocation for Dummies?

NSInvocation工作究竟如何?有一个很好的介绍吗?

我特别关注以下代码(来自Cocoa Programming for Mac OS X,3rd Edition)的工作原理,但是也可以独立于教程示例应用这些概念.代码:

- (void)insertObject:(Person *)p inEmployeesAtIndex:(int)index
{
    NSLog(@"adding %@ to %@", p, employees);
    // Add inverse of this operation to undo stack
    NSUndoManager *undo = [self undoManager];
    [[undo prepareWithInvocationTarget:self] removeObjectFromEmployeesAtIndex:index];
    if (![undo isUndoing])
        [undo setActionName:@"Insert Person"];

    // Finally, add person to the array
    [employees insertObject:p atIndex:index];
}

- (void)removeObjectFromEmployeesAtIndex:(int)index
{
    Person *p = [employees objectAtIndex:index];
    NSLog(@"removing %@ from %@", p, employees);
    // Add inverse of this operation to undo stack
    NSUndoManager …
Run Code Online (Sandbox Code Playgroud)

cocoa objective-c undo-redo

138
推荐指数
3
解决办法
6万
查看次数

标签 统计

cocoa ×1

objective-c ×1

undo-redo ×1