问题标签 [nstextfieldcell]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
34 浏览

testing - How to get contents of a NSTextFieldCell in a cell-based outline when the user quits while editing

The previous version of this question was closed because the moderator did not recognize that this is a cell-based Outline not a view-based outline. The answer the moderator suggested does not work for a cell-based outline.

The question as previously asked was:

I have a cell-based NSOutlineView. How do I get the contents of the NSTextFieldCell when the user Quits the app while editing that cell. Currently, attributedStringValue returns the contents before editing began.

As requested in the comments, here is a NSViewController.h and .m . It references a storyboard with two outlets: outlineView and cellOutlet as shown in viewController.h.

ViewController.h

and ViewController.m

0 投票
1 回答
32 浏览

xcode - 如何在 Swift 5 中为基于单元格的 NSTableVew 中的单个行着色

我试图在其中显示项目,NSTableView但其中一个项目(先前由操作激活的项目(其名称存储在alreadyActivatedItem变量中))应该被禁用并以红色文本显示。

到目前为止,我设法使禁用正常工作。

我只是无法将已激活的项目着色为红色文本。我下面的代码会将所有单元格的文本涂成红色。

我还尝试了另一种方式:

在这两种情况下,我都会有所有带有红色文本的行:

看到所有项目都是红色文本

在调试时,我可以看到:

  • let c = cell as? NSTextFieldCell似乎得到了当前行的单元格,至少我得到了stringValue正确的行c.stringValue
  • if c.stringValue == alreadyActivatedRow似乎工作得很好,至少它只有在条件为真时才会进入。

那么为什么所有的物品仍然是红色的呢?

那如何实现我的目标呢?

(Xcode 11.3.1,斯威夫特 5.1.3)

0 投票
0 回答
22 浏览

swift - 为继承的 NSTextFieldCell 设置自定义 objectValue

我已经成功创建了一个继承自NSTextFieldCell. 自定义单元格需要返回一个自定义对象,而不是 textview 字符串。对于上下文,我正在尝试模拟系统偏好设置/键盘中的快捷方式网格。

到目前为止,我已经在 keyDown 上创建了自定义对象,但不确定如何返回它以在表中使用。

我将在哪里/如何设置我的对象以便可以从 tableView 中读取它?

这是我想使用单元格中的自定义对象的地方。