0

I am trying to find a way to initialise a view controller which has IBOutlets to a custom view that I have created in a XIB.

Here is the code where I initialise my class:

MyContentViewController *pageContentViewController = [[MyContentViewController alloc] init];
self.pageContent = pageContentViewController;
[pageContentViewController view];

MyContentViewController has the following properties:

 @interface MyContentViewController : UIViewController

 @property (nonatomic, weak) IBOutlet MyContentView *topLeftView;
 @property (nonatomic, weak) IBOutlet MyContentView *topRightView;
 @property (nonatomic, weak) IBOutlet MyContentView *bottomLeftView;
 @property (nonatomic, weak) IBOutlet MyContentView *bottomRightView;

In MyContentViewController xib I have 4 views which I have set as MyContentView and have hooked the IBOutlet's above to the views in the storyboard.

enter image description here

The custom view is defined as following:

#import <UIKit/UIKit.h>

@interface MyContentView : UIView

@property (nonatomic, strong) IBOutlet UILabel *labelView;

 @end

However when I run the application, I get the 4 views I have added in the MyContentViewController xib. However none of them display the UILabel from the custom UIView.

I have added the following in MyContentView:

- (void)awakeFromNib {
    NSLog(@"VIEW AWAKE");
}

This get printed out so the views are being loaded. However how can I get them to display using the 4 IBOutlets.

Here is a picture of the app running with the view. There is no labels on the 4 views: enter image description here

4

1 回答 1

1

我看到您的“MyContentView”有一个自己的笔尖。从另一个 nib 加载具有 nib 布局的自定义 UIView 类有点复杂。

我认为这篇文包含了答案

于 2015-07-21T10:01:29.560 回答