-1

I created a TutorialScreen subclass of UIView, and in a xib file I created three UIViews of that type and used them in another class by bringing those objects into UIViews:

self.tutorialScreen1 = [[[NSBundle mainBundle] loadNibNamed:@"View" owner:nil options:nil] objectAtIndex:0];
self.tutorialScreen1.translatesAutoresizingMaskIntoConstraints = NO;
self.tutorialScreen1.layer.cornerRadius = 8.0;
self.tutorialScreen1.alpha = 0.0;
[self.notificationWindow addSubview:self.tutorialScreen1];

In the xib file, each UIView has a UILabel in the middle that I created an outlet for (and linked all three UIViews to), called textLabel.

But in that class I created tutorialScreen1 in, when I do the following:

NSLog(@"%@", self.tutorialScreen3.textLabel.text);

Every time that outputs (null). Why on earth is it doing that? The label is explicitly set to "text" so I don't see why it keeps calling it null. I can't manipulate it at all because the label doesn't seem to exist.

Doug Smith
  • 29,668
  • 57
  • 204
  • 388
  • did not see creation of tutorialScreen3 variable. you are creating tutorialScreen1 and logging tutorialScreen3. Please make sure creation and initialization of tutorialScreen3 before logging. – sohail059 Nov 08 '13 at 03:48
  • Yes, tutorialScreen3 does indeed get created. Identically to tutorialScreen1. – Doug Smith Nov 08 '13 at 03:51
  • did you make its outlet? you can access nib object by making its connection with code variable – sohail059 Nov 08 '13 at 04:08
  • Try logging the class of self.tutorialScreen to make sure it's correct, and also self.tutorialScreen3 to see if it's null. – rdelmar Nov 08 '13 at 05:31
  • Here's a sample project recreating the issue: http://cl.ly/3O3M232f1q0R It is an outlet, and I logged self.tutorialScreen3 and it isn't null, though I'm not sure what you mean by logging the class. – Doug Smith Nov 08 '13 at 15:06

1 Answers1

1

Did you create outlet of all the views if yes then create outlet of UILabel also after when you click on any button e.t.c present that view which you want.

Gurpreet
  • 181
  • 6
  • Gurpreet is right,you have to create and connect outlets and set file owner of View to viewcontroller. – Rajpal Thakur Nov 08 '13 at 05:38
  • I believe I created outlets to all the views I'm accessing, though I'm not totally sure what you mean. Here's an example project recreating it: http://cl.ly/3O3M232f1q0R What do you mean with the file owner thing, Dheerendra? – Doug Smith Nov 08 '13 at 15:07
  • Hello Doug Smith I have solved your problem the problem is you have created the outlet of label in another view but you present the Moving & Test view thats why they show null. I have attached your project here check it :- https://github.com/preetlotey999/Nib-Label-Test.git. I have created a Blog for Developers to make it easy for Developing. For any help you can go through it & if you have any query you can also post you question here :- http://preetlotey999.blogspot.in/ Thanks. – Gurpreet Nov 09 '13 at 04:58