0
votes

I added a custom view class with its own xib. In the xib, File's Owner -> Custom Class is set to "MyCustomView".

I added a blank view in my storyboard with class set to "MyCustomView"

When I run my app, I don't see my view being displayed properly. However, I do see 2013-03-01 16:52:48.283 Test[56785:c07] MyCustomView initWithCoder

Any ideas what went wrong?

I have isolated this error here: http://bit.ly/YdDbqU

Thanks!

EDIT:

  1. I turned off autolayout
  2. I used the following:

    UIView *subview = [[NSBundle mainBundle] loadNibNamed:@"MyCustomView" owner:self options:nil].lastObject; subview.frame = self.myCustomViewInstance.bounds; [self.view addSubview:subview];

  3. Any everything worked!

3
What does "displayed properly" mean. I see a blank, white, UIView, as it should beCodaFi
@CodaFi well the xib has a few labels: 1, 2, 3, 4, ... I was referring to that xib being displayed on the white space of the main viewdisappearedng

3 Answers

1
votes

You never actually load that xib -- setting the class in IB isn't enough. You still need to load the xib file, and set your controller's view to that view;

#import "FirstViewController.h"
#import "MyCustomView.h"

@implementation FirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view = [[NSBundle mainBundle] loadNibNamed:@"MyCustomView" owner:self options:nil].lastObject;
} 
0
votes
  1. I turned off autolayout
  2. I used the following:

    UIView *subview = [[NSBundle mainBundle] loadNibNamed:@"MyCustomView" owner:self options:nil].lastObject; subview.frame = self.myCustomViewInstance.bounds; [self.view addSubview:subview];

Any everything worked!

0
votes

Make sure your class is a inherits from UIViewController.

@interface ClassName : UIViewController