0

Here's a sample project recreating the issue: http://cl.ly/3O3M232f1q0R

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

1 Answers1

2

You didn't connect the outlets:

enter image description here


enter image description here

A-Live
  • 8,904
  • 2
  • 39
  • 74
  • Added an outlet to `textLabel` in the .h file still did nothing. – Doug Smith Nov 08 '13 at 19:08
  • @Doug Smith That's not how you connect it. See the second screenshot. – A-Live Nov 08 '13 at 19:12
  • Is it possible to do this with constraints as well? I'm trying to but failing miserably to be able to access them in code, even if I connect them in the above way. (Say I connect an Auto Layout constraint from the top of the text label to its superview.) – Doug Smith Nov 08 '13 at 20:18
  • @Doug Smith I don't know :) – A-Live Nov 08 '13 at 20:26
  • @DougSmith, yes you can make IBOutlets to layout constraints. You can make them from the constraints you see when you select a view, but sometimes it's easier to select them from the Scene list. – rdelmar Nov 09 '13 at 03:34