-1

I have created Empty control - LogonErrorMessage.xib. In interface builder placed there a View control and inside it placed a label - kind of created custom message control.

Then i created Objective-C class that is named also LogonErrorMessage.h and LogonErrorMessage.m.

Then in LogonErrorMessage.xib i selected View control and in "Custom class" section changed class to LogonErrorMessage, to tie the *.xib to class.

Now i'm trying to do this on my MainViewController:

LogonErrorMessage *logonError = [[LogonErrorMessage alloc] init];
logonError.iboMessageText.text = message;
logonError.frame= CGRectMake(0, 0, 307, 100);
[self.view addSubview:logonError];

And the message control doesn't show up - what is the problem?

Developer
  • 4,158
  • 5
  • 34
  • 66
  • possible duplicate of [Subviews for custom UIView with Nib (.xib) don't load?](http://stackoverflow.com/questions/19137846/subviews-for-custom-uiview-with-nib-xib-dont-load) – Lord Zsolt Jun 03 '14 at 08:22

1 Answers1

1

Replace your first line:

LogonErrorMessage *logonError = [[LogonErrorMessage alloc] init];

With

//Loads all views named "MyView", in your case, replace "MyView" with your xib name.
NSArray *allCustomViews = [[NSBundle mainBundle] loadNibNamed:@"LogonErrorMessage" owner:self options:nil];

//Assuming there's only one MyView.xib
LogonErrorMessage* customView = [allCustomViews firstObject];
Lord Zsolt
  • 6,492
  • 9
  • 46
  • 76