0

I created an objective-c class "customTable.h" subclassing UIView.

I then created a custom View in XIB. I went to the identity inspector and under custom class I chose the name of the class I created (customTable) as file's owner. In the customTable View in the xib I added a couple UILabels and a subview. For the subview I selected it and went under custom class and chose another custom class 'menuTable.'

In the customTable.h file I have linked the menuTable from the XIB as an IBOutlet, because I want to be able to do some configuration of the outlet in the view's initialization.

in the customTable.m file I have:

- (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 */
}

In Storyboard I added a subview to a ViewController's view and then told storyboard I wanted the subview to use the custom class "customTable." In the viewcontroller's .h file I linked this view as an IBOutlet.

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

When I run it in simulator the subview doesn't show up in the viewcontroller. I added some break points to the customTable.m file and the initialize methods are being called. So why is it not appearing?

4

2 回答 2

1

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

于 2013-11-08T01:47:55.020 回答
0

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

于 2013-11-08T02:53:08.470 回答