如何命名撤消菜单条目Core Data通过绑定和NSArrayController添加/删除项目? [英] How to name Undo menu entries for Core Data add/remove items via bindings and NSArrayController?

查看:122
本文介绍了如何命名撤消菜单条目Core Data通过绑定和NSArrayController添加/删除项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 NSTableView 填充一个核心数据实体和添加项目/删除项目按钮所有有线与 NSArrayController

I have a NSTableView populated by a Core Data entity and Add Item / Remove Item buttons all wired with a NSArrayController and bindings in Interface Builder.


$ b

撤消/重做菜单项可以撤消或重做添加/删除项操作。

The Undo/Redo menu items can undo or redo the add / remove item actions.

但是菜单项仅被称为撤消。 redo。

我如何命名他们像撤消添加项目,撤消删除项目等。

But the menu entries are called only „Undo" resp. „Redo".
How can i name them like „Undo Add Item", „Undo Remove Item", etc.

,之前提出过类似问题,但接受的答案是一个单一的,现在烂的链接对子类 NSManagedObject 的建议,并覆盖Apples文档所说的方法:重要:你不能重写这个方法)

(I am aware, something similar was asked before, but the accepted answers are either a single, now rotten link or the advice to subclass NSManagedObject and override a method that Apples documentation says about: "Important: You must not override this method.")

推荐答案

将NSArrayController的子类添加为项目中的一个文件在xib中,数组控制器的Identity Inspector,将类从 NSArrayController 更改为新的子类。

Add a subclass of NSArrayController as a file in your project. In the xib, in the Identity Inspector of the array controller, change the Class from NSArrayController to your new subclass.

覆盖 - newObject 方法。

- (id)newObject
{
    id newObj = [super newObject];

    NSUndoManager *undoManager = [[[NSApp delegate] window] undoManager];
    [undoManager setActionName:@"Add Item"];

    return newObj;
}

- remove:sender 方法。

- (void)remove:(id)sender
{
    [super remove:sender];

    NSUndoManager *undoManager = [[[NSApp delegate] window] undoManager];
    [undoManager setActionName:@"Remove Item"];
}

这篇关于如何命名撤消菜单条目Core Data通过绑定和NSArrayController添加/删除项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆