自定义控制相当于X code / MonoMac [英] Custom Control equivalent in XCode/MonoMac

查看:196
本文介绍了自定义控制相当于X code / MonoMac的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个.NET开发人员尝试他的手在一个Windows应用程序的OSX端口。我使用的MonoDevelop和MonoMac(与C接口生成器的X $ C $)创建我的UI。

I'm a .NET developer trying his hand at an OSX port of a Windows application. I'm using MonoDevelop and MonoMac (with the XCode Interface Builder) to create my UI.

即将从Windows,我想了解可可相当于一个用户控件,因为我在我的WinForm的版本中使用这些广泛。我有一组控件(比方说一个标签,文本框和按钮),我想打包并重复使用在不同的地方在我的可可UI。

Coming from Windows, I'm trying to understand the Cocoa equivalent of a "UserControl" since I used these extensively in my WinForm version. I have a group of controls (let's say a label, textbox and button) that I want to package up and reuse in various places throughout my Cocoa UI.

据我了解,我需要创建一个自定义视图的子类的NSView(姑且称之为MyView的)。我可以在Interface Builder创建的MyView的好了,但是当我使用它在我的主窗口,它总是显示为空/空。

From what I understand, I need to create a "custom view" by subclassing NSView (let's call it "MyView"). I can create "MyView" in the Interface Builder alright, but when I use it on my main window it always appears empty/blank.

下面是我如何将控制在我的主要形式,IB:我从对象库中添加自定义视图(的NSView),然后在自定义类到MyView的改变阶级属性。这不是一个问题,如果控制不呈现在设计时,但它是完全空在运​​行了。

Here's how I'm placing the control on my main form in IB: I add a Custom View (NSView) from the object library, then change the "class" property under "Custom Class" to "MyView". It's not a problem if the control doesn't render at design time, but it's totally empty at runtime too.

我怀疑我失去了一些东西很简单/显而易见的。是自定义视图应该这样使用?所有我在网上找到的例子似乎讨论自定义绘制,这是我不希望(我只是想用一堆控制起来,所以我可以重新使用它们)。人在那里都可以阐明一些这我吗?

I suspect I'm missing something really simple/obvious. Are custom views supposed to be used this way? All the examples I've found online seem to discuss custom drawing, which I don't want (I just want to use a bunch of controls together so I can reuse them). Can anyone out there shed some light on this for me?

在此先感谢。

推荐答案

如果你只是想要一组标准控件,那么你可能需要一个独立的视图NIB /厦门国际银行。然后,你会加载NIB每次要实例化集团,从它那里得到的顶层视图,并插入这一观点为其它的视图层次。你会使用 NSViewController (或自定义子类)拥有和加载NIB。

If you just want a group of standard controls, then you may want a standalone view NIB/XIB. Then you'd load that NIB each time you want to instantiate that group, get the top-level view from it, and insert that view into some other view hierarchy. You'd use an NSViewController (or a custom subclass) to own and load that NIB.

您还可以添加一个自由站立以笔尖已包含,比如说,一个窗口。笔尖的所有者( NSWindowController 或子类的经常的实例)将有一个出口来指自由站立视图层次。您的code可以再使用该视图层次的意愿,将其插入到窗口的视图层次结构的适当地方。

You can also add a free-standing view to a NIB that already contains, say, a window. The NIB's owner (often an instance of NSWindowController or a subclass) would have an outlet to refer to that free-standing view hierarchy. Your code could then use that view hierarchy at will, inserting it into the window's view hierarchy at an appropriate place.

您通常不使用自定义视图类只是为了集团的标准控制。你只需做一个视图子类,使一个非标准的观点,一个画在一个自定义的方式,或提供了不同的操作技术。

You don't typically use a custom view class just to group standard controls. You only make a view subclass to make a non-standard view, one that draws in a custom manner or provides a different manipulation technique.

这篇关于自定义控制相当于X code / MonoMac的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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