0
votes

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?

2
Do you mean the IBOutlet is set to nil or that the element isn't visible in the view controller? - Ben Flynn
The element isn't visible in the view controller. - user1066524
are you using the init or initWithFrame? can you try add a background color to your view. - TreeTree
initWithFrame. I tried adding a background to the view and nothing appeared, so that tells me that the view isn't being loaded. - user1066524

2 Answers

1
votes

My suggestion is in your storyboard, drag drop the "Container View" on top of your main view. This will create a container with a connection to new view controller in your storyboard. You then select new view controller and set the custom view to your CustomTable in the identity inspector. BTW, capitalize your class CustomTable since it's class.

0
votes

I think I figured it out. The reason this was happening was that I was supposed to select "With XIB for user interface" when I created the class.