【问题标题】:Interface Builder does not see my subclassed UILabelInterface Builder 看不到我的子类 UILabel
【发布时间】:2012-06-30 03:01:33
【问题描述】:

在 MonoTouch 中,我定义了以下类:

using System;
using MonoTouch.UIKit;
using MonoTouch.Foundation;
using System.Drawing;

namespace MyApp
{
    public class WUILabel : UILabel
    {
        public WUILabel () : base() { this.SetDefaults(); }
        public WUILabel(NSCoder coder) : base(coder) { this.SetDefaults(); }
        public WUILabel(NSObjectFlag t) : base(t) { this.SetDefaults(); }
        public WUILabel(IntPtr handle) : base(handle) { this.SetDefaults(); }
        public WUILabel(RectangleF frame) : base(frame) { this.SetDefaults(); }

        private void SetDefaults()
        {
            this.Font = UIFont.FromName("AmericanTypewriter", 15f);
            this.TextColor = UIColor.Black;
        }
    }
}

在 Interface Builder 中,我将标签的“Class”属性设置为“WUILabel”。

当我运行应用程序时,应用程序输出包含错误“Interface Builder 文件中的未知类 WUILabel”。有没有人成功地让它工作,或者谁能告诉我我做错了什么?

【问题讨论】:

    标签: xamarin.ios interface-builder uilabel subclass


    【解决方案1】:

    你必须用 RegisterAttribute 来装饰你的类。

    检查this的答案。

    【讨论】:

    • 谢谢,迪米特里斯!当你的答案通过时,我刚刚弄清楚并发布了我的答案。
    • 我的班级被装饰了,但我仍然收到错误消息。这只发生在设备上运行时,我可以使用 xcode 管理器控制台看到错误。在模拟器中一切都很好......
    • 重新启动 xamarin 并清理构建后,事情得到了修复
    猜你喜欢
    • 1970-01-01
    • 2011-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-04
    • 1970-01-01
    • 2012-08-21
    • 1970-01-01
    相关资源
    最近更新 更多