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 trialKevin Baier
2,597 PointsDon't understand what is wrong with this syntax: self.quoteLabel.text = @"A stitch in time saves nine";
Code challenge IBActions and IBOutlets: Question: Assume we're creating an app that tells us random quotes. We have a label in our view that's connected to a ViewController.h file using an IBOutlet. We also have a button connected to a quoteButtonPressed:(id)sender action. When we tap the button, we want to show the user a quote. Assign the string "A stitch in time saves nine." to the quoteLabel.
#import "UIViewController.h"
#import "UILabel.h"
@interface ViewController: UIViewController
@property (strong, nonatomic) IBOutlet UILabel *quoteLabel;
- (IBAction)quoteButtonPressed; {
self.quoteLabel.text = @"A stitch in time saves nine";
}
@end
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)quoteButtonPressed {
@property (strong, nonatomic) IBOutlet UILabel *quoteLabel;
}
@end
2 Answers
Steve Hunter
57,712 PointsHi Kevin,
You've implemented your method in the .h
file. It just gets declared there.
If you add your line of code to the implemented method in ViewController.m
you should get a different result.
The .h
file just has the skeleton of the method so it should just look like:
- (IBAction)quoteButtonPressed;
The method is implemented in the .m
file and should look like:
- (IBAction)quoteButtonPressed {
self.quoteLabel.text = @"A stitch in time saves nine";
}
You also copied your @property into the implementation. Just leave that in the .h
and all will be fine.
Let me know if this doesn't work - it's wholly possible!!
Steve.
Kevin Baier
2,597 PointsYou know, I think it was just because I forgot to add a period at the end of the label text. Anyway, I redid the challenge tonight and got it. Thanks for your assistance!