简体   繁体   English

从.xib文件加载了接口的自定义UIView类中的错误

[英]Error in custom UIView class having interface loaded from .xib file

I want to make a reusable UIView which I will use in several UIViewController s. 我想制作一个可重用的UIView ,它将在几个UIViewController使用。 So I added a .xib file in my project and I drawn my interface, I added a class inherited from UIView and then I set up .xib class type same as the new class I have just added. 因此,我在项目中添加了.xib文件,并绘制了界面,添加了从UIView继承的类,然后设置了与刚刚添加的新类相同的.xib类类型。

Next I dragged a outlet for .xib's main view in corresponding .h . 接下来,我在相应的.h中拖动.xib主视图的出口。

In myCustomUIView class I wrote this code to load the interface from .xib but it crashes at the line where I'm trying to load the nib file. myCustomUIView类中,我编写了这段代码以从.xib加载接口,但是在我尝试加载nib文件的那一行崩溃。 Unfortunately compiler doesn't give me any error/reason. 不幸的是,编译器没有给我任何错误/原因。 Please help me. 请帮我。

-(void)awakeFromNib
{
    [[NSBundle mainBundle] loadNibNamed:@"DropDownMenuViewInterface" owner:self  options:nil];
    [self addSubview: self.customView];
}

在此处输入图片说明

Did you setup File Owner for this xib? 您是否为此xib设置了文件所有者? Check my image 查看我的图片 在此处输入图片说明

Instead of subclassing root view in you xib hierarchy - make the File Owner to be your view subclass 而不是在您的xib层次结构中将根视图子类化-让文件所有者成为您的视图子类

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM