在类中创建自定义操作以在Interface Builder中使用 [英] Create custom action in a class for use in Interface Builder

查看:126
本文介绍了在类中创建自定义操作以在Interface Builder中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在一个类中创建一个自定义操作连接,该连接应该在Interface Builder中可见.例如-我将动作/目标属性添加到NSView类中,如下所示:

I want to create a custom action connection in a class, which should be visible in Interface Builder. For example - I add action / target properties to NSView class just like this:

weak open var object: AnyObject?    
open var something: Selector?

操作为something,目标为object. 现在,我希望在Interface Builder中为something提供发送动作"链接/连接,并能够将与@IBAction方法的连接建立到某个类(例如视图的控制器),就像它可以通过简单的NSButton完成.也许这是不可能的,或者我必须在自定义操作/目标对之前添加一些关键字,就像我们需要使属性@IBInspectable出现在Attributes Inspector中一样.

The action is something and the target is object. Now I want in Interface Builder to have 'Send Action' link / connection available for something and to be able to make connection to a @IBAction method to some class (for example the controller of the view), just like it can be done for a simple NSButton. Maybe this is not possible, or maybe I must add some keywords in front of the custom action / target pair, the same way we need to make a property @IBInspectable to appear in Attributes Inspector.

欢迎任何帮助;-)

推荐答案

我认为您无法做到这一点.您可以将@IBInspectable属性添加到自定义NSView子类中,但是属性没有选择器或操作数据类型.唯一允许的类型是布尔值,数字,字符串,本地化字符串,点,大小,矩形,范围,颜色,图像,无.

I don't think you can do that. You can add @IBInspectable properties to custom NSView subclasses, but there is no selector or action data type for properties. The only allowed types are Boolean, Number, String, Localized String, Point, Size, Rect, Range, Color, Image, Nil.

Interface Builder具有对处理控件的目标动作属性的硬连线支持.

Interface Builder has hard-wired support for handling the target-action properties of controls.

(顺便说一句,您可能应该将Mac OS标签添加到您的问题中.此板上的大多数Apple流量与iOS相关.

(BTW you should probably add the Mac OS tag to your quesiton. Most Apple traffic on this board is iOS-related.

正如某人在评论中所说,如果您要创建一个具有目标/动作的对象,则该对象可能应该是NSControl,而不是NSView.控件是处理目标动作的对象系列,Interface Builder中有一种机制可以向控件添加目标/动作.

As somebody said in a comment, if you're creating an object that has a target/action, it should probably be an NSControl, not an NSView. Controls are the object family that handle target-actions, and there IS a mechanism in Interface Builder for adding target/actions to controls.

这篇关于在类中创建自定义操作以在Interface Builder中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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