Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Simple iPhone App (iOS7) Getting Started What Is an IBOutlet?

Crystal Ball Help

Hi. I am having a slight issue with my Xcode. I put this code into my ViewController.h

@interface MJViewController : UIViewController @property (strong, nonatomic) IBOutlet UILabel *predictionLabel;

  • (IBAction)buttonPressed; @end

And then this code into the ViewController.m

  • (IBAction)buttonPressed { self.predictionLabel.text = @"YES"; }

My problem is when I build it and run the iOS Simulator the predict button disappears. Any help would be greatly appreciated. Thanks.

-MJ

Not sure this will solve your problems, but just a tip: Set a weak pointer to the label instead of strong like this:

@property (weak, nonatomic) IBOutlet UILabel *predictionLabel;

You don't need to point to it strongly. When you, for example, push another view controller on top of this one, the label will disappear anyway, so do this do avoid a memory leak.

13 Answers

Stone Preston
Stone Preston
42,016 Points

did you connect your button from your storyboard to your interface file? (control + click and drag from the button in storyboard to your .h file). If all you did was manually add the code by typing it in nothing is going to happen, you have to connect the two files (storyboard and your class file) together. There are several ways to do this but control + clicking and dragging is the easiest in my opinion

Hey, thanks for the reply. I did link it by dragging it in.

Stone Preston
Stone Preston
42,016 Points

did you set your storyboard as the main interface file in your project settings (click the blue xcode icon at the top of your project tree with your project name above it - > General - > main interface -> set the main interface as your storyboard). Supposedly you dont have to do this in the new version of Xcode but you could try it and see if it works

Hey I tried it out with no luck. I am thinking maybe it is the iOS Simulator, the app builds successfully but then when I go to see it I am now just greeted with a black screen. I have had Xcode for a few days now and this is already giving me trouble..

Stone Preston
Stone Preston
42,016 Points

Did you set the view controllers class in storyboard to your custom class?

have you already applied the autoLayout concept on the app.

Patrick Cooney
Patrick Cooney
12,216 Points

Could be the auto-layout. Try this first though, make sure you are using the correct form factor in the simulator. If you design on a storyboard for the iphone 5 or 5s (4" screen) and run it on the iphone simulator for one of the 3.5" screens stuff starts to disappear. With the simulator running go up to the menu bar, find "device" and switch it to iphone 5 or 5S. Alternatively, you can swap the storyboard to use 3.5" form factor. That one is a little button somewhere in the storyboard canvas window.

Stone Preston
Stone Preston
42,016 Points

he said its just a black screen, so I dont think auto layout is the issue.

Patrick Cooney
Patrick Cooney
12,216 Points

I didn't read that far down. I just saw the initial question (which my answer was to) and the last answer about auto-layout (which I was addressing in the first sentence). This was when I thought it was just a disappearing button which happens all the time on the wrong form factor simulator.

Stone Preston
Stone Preston
42,016 Points

Patrick Cooney yeah you are probably right about the button disappearing because of the different simulator heights. However still not sure what the black screen bit is.

Hey, thanks for all your suggestions. Yeah I am at the in @property and NSArray portion of this stage and now when i build my app I just get a black screen. I've tried reset content and settings as well as just rebooting the computer to see if this would make a difference (it doesn't). It went from the button disappearing to everything disappearing.

Patrick Cooney
Patrick Cooney
12,216 Points

Was the screen black before you started messing around with things people told you to do or was it still white but just with no button?

I was good to go when I first started the course - the button appeared when it was a simple NSLog then when I got into the IBAction that's when the button decided not to show. Then, getting into the videos on CGRect and Frame and following them - that is when it seemed the whole app just disappeared.

Stone Preston
Stone Preston
42,016 Points

ok so it was working before, and then you started getting the black screen? Did you change the name of your view controller files or anything?

I should mention too - that I just got this message "SpringBoard failed to launch application with error: -3" Anybody have any suggestions on this little problem? Perhaps, that's why I keep getting this black screen.

Stone Preston
Stone Preston
42,016 Points

thats a problem with the simulator itself. Happens every so often. To fix it try switching simulators (from 3.5 to 4) or restarting xcode.

Patrick Cooney
Patrick Cooney
12,216 Points

Springboard is what launches the apps for you. I think something you did screwed up the settings the app needs to launch itself. Hard to say what without looking at it though. The one time I had something like that happen it was from screwing with the default storyboard.

Stone Preston
Stone Preston
42,016 Points

its a recurring problem with Xcode 5 it seems. see here for more possible althought temporary fixes.

Hey, no I didn't change the name of the view control files. I've just been following along with what the videos state and somehow I am getting this.

Stone Preston
Stone Preston
42,016 Points

ok in your storyboard go your viewController, open the identity inspector and verify the view controller is using your custom view controller class.

Hey, I've decided to start over, thinking maybe I had screwed something up. It was actually working button displayed using

  • (IBAction)buttonPressed { NSLog(@"Button Pressed"); }

It's when I put in the view controller.h

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

then this into the view controller.m

  • (IBAction)buttonPressed { self.predictionLabel.text = @"YES"; }

It's exactly how it is in the video - this is when the button doesn't display. My label that says, "It is decidedly so" still shows up. Everything is connected too. I just wanted to pinpoint the exact moment it happened.

Stone Preston
Stone Preston
42,016 Points

as Patrick Cooney mentioned, it could be the size of the simulator and auto layout causing this. Try moving your button somewhere up higher on the view near the top, then cleaning your product by selecting product -> clean from the xcode menu, then running. See if it shows up. I wouldnt start over yet

Alright, it's working! Thanks for the help! You guys are F*#%ing awesome!

May or may not be related, but in the video when the label is dragged to create the IBOutlet property, the auto-generated code has a strong reference, whereas, when I drag it (on XCode 5.1.1), the reference is weak:

@property (weak, nonatomic) IBOutlet UILabel *predictionLabel;

Stone Preston
Stone Preston
42,016 Points

it should be weak. your label is a child of the viewController. Whenever you have parent child relationships like that (most often between your view controller and controls like labels and buttons etc) you use weak.

You could always choose it to be strong or weak from the drag down menu option.... Its not at all an issue i guess... strong attribute tells the compiler that it will not be destroyed until the programmer wants (assigns a nil value) and weak attribute tells the compiler that it will last till any ( atleast one) object is referring to it or holding it and after that it will be destroyed (deleted ) from the memory.

I hope it helps.....