繁体   English   中英

UIViewController中的自定义子视图未出现

[英]Custom subview in UIViewController not appearing

我创建了UIView的Objective-C类“ customTable.h”子类。

然后,我在XIB中创建了一个自定义视图。 我去了身份检查器,在自定义类下选择了我创建的类的名称(customTable)作为文件的所有者。 在xib的customTable视图中,我添加了几个UILabel和一个子视图。 对于子视图,我选择了它并进入自定义类,然后选择了另一个自定义类“ menuTable”。

在customTable.h文件中,我已将XIB中的menuTable链接为IBOutlet,因为我希望能够在视图的初始化中对插座进行一些配置。

在customTable.m文件中,我有:

- (id)init
{
    if(self = [super init])
    {
        [self initialize];
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
         [self initialize];
    }
    return self;
}

- (id)initWithCoder:(NSCoder *)aDecoder
{
    if(self = [super initWithCoder:aDecoder])
    {
        [self initialize];
    }
    return self;
}
- (void)initialize
{
    /*some special configuration code for menuTable
    is here */
}

在情节提要中,我向ViewController的视图添加了一个子视图,然后告诉情节提要,我希望该子视图使用自定义类“ customTable”。 在viewcontroller的.h文件中,我将此视图链接为IBOutlet。

@property (weak, nonatomic) IBOutlet customTable *cView;

当我在模拟器中运行它时,子视图不会显示在viewcontroller中。 我在customTable.m文件中添加了一些断点,并调用了initialize方法。 那么为什么它不出现呢?

我的建议是在您的情节提要中,将“容器视图”拖放到主视图顶部。 这将创建一个容器,该容器具有连接到故事板上的新视图控制器的连接。 然后,选择新的视图控制器,然后在身份检查器中将自定义视图设置为CustomTable。 顺便说一句,因为类CustomTable是大写的,所以要大写。

我想我知道了。 发生这种情况的原因是,我在创建类时应该选择“使用XIB作为用户界面”。

暂无
暂无

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

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