如何自定义视图添加到MonoTouch的一个XIB文件定义的视图 [英] How to add a custom view to a XIB file defined view in monotouch

查看:145
本文介绍了如何自定义视图添加到MonoTouch的一个XIB文件定义的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想此刻学习MonoTouch的,并按照麦克BlueStein的学习MonoTouch的书籍。没有一本坏书,但它因为x code 4(我相信)和MonoTouch的一个较新的版本稍微过时的已经出来了。

I'm trying to learn monotouch at the moment, and following the learn monotouch book by Mike BlueStein. Not a bad book, but it's slightly outdated since xcode 4 (i believe) and a newer version on monotouch has come out.

不管怎么说,在我的项目我有一个控制器和一个XIB文件。我也有一个自定义视图(如MyView的:UIView的),即覆盖绘制方法。我想告诉我的自定义视图旁边或者在厦门国际银行文件中定义的视图的顶部。我该怎么做呢?

Anyways, in my project I have a controller and a xib file. I also have a custom view (e.g. myview : UIView), that overrides the draw method. I want to show my custom view next to or on top of the view defined in the xib file. How do I do this?

在控制器中,如果我重写的loadView方法,并在视图设置为我的自定义视图的一个实例,然后我可以看到它,但我失去了厦门国际银行文件中定义的一切。如果我尝试添加为子视图,它不会出现在所有。

In the controller, If I override the LoadView method, and set the View to an instance of my custom view, then I can see it, but I loose everything defined in the xib file. If I try to add as a sub view, it does not appear at all.

我在想什么?如果问题是不明确的,请让我,让我可以澄清一下。

What am I missing? If the question is not clear, please ask me, so I can clarify.

干杯。

推荐答案

请按照下列步骤在厦门国际银行使用自定义视图:

Follow the following steps to use a custom view in a XIB:

首先,装饰与视图的 RegisterAttribute

[Register("MyView")]
public class MyView : UIView
{
}

和执行下面的构造:

public MyView(IntPtr handle) : base(handle) {}

是需要时,运行时将尝试重新创建视图它已被内存警告后销毁此构造。你创建自定义类后:

This constructor is needed for when the runtime will try to recreate the view after it has been destroyed by a memory warning. After you have created your custom class:


  • 在X code(总是通过双击它通过MonoDevelop的)打开厦门国际银行,并添加的UIView 您想要的位置。

  • 在X code,设置的UIView的类MyView的(或者你传递给任何名称 RegisterAttribute

  • Open the XIB in Xcode (always by double-clicking on it through MonoDevelop) and add a UIView where you want it.
  • In Xcode, set that UIView's class to MyView (or whichever name you passed to the RegisterAttribute):


  • 编译运行。

编辑:

不覆盖的loadView 对于那些从厦门国际银行加载控制器。 的loadView 是为了创建时,不从厦门国际银行加载的控制器的视图控制器的看法。

Do not override LoadView for controllers that are loaded from a XIB. LoadView is meant to create the controller's view when that controller's view is not loaded from a XIB.

这篇关于如何自定义视图添加到MonoTouch的一个XIB文件定义的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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