I wanted to add a string to a label and tried different things.
So this is what my code looks like:
@interface DeviceControl : UIViewController
@property (weak, nonatomic) IBOutlet UIView *intensityLevelView;
@property (weak, nonatomic) UILabel *intensityLabel;
- (IBAction)intensitySliderDragged:(id)sender
@end
@synthesize intensityLabel;
@synthesize intensityLevelView;
- (IBAction)intensitySliderDragged:(id)sender {
intensityLevel = intensitySlider.value;
int newIntensityLevel = (int)intensityLevel; //because intensityLevel is a float and I needed an integer.
intensityLabel = (UILabel*)[intensityLevelView viewWithTag:10];
NSString *string = [NSString stringWithFormat:@"Intensity is at %d",newIntensityLevel];
intensityLabel.text = string;
NSLog(@"string = %@", string);
NSLog(@"label text = %@",intensityLabel.text);
}
That didn't work so I tried these too:
intensityLabel.text = [intensityLabel.text stringByAppendingFormat:@"%d",newIntensityLevel];
intensityLabel.text = [NSString stringWithFormat:@"Intensity is at %d", newIntensityLevel];
And I was so frustrated that I even tried this if that worked:
intensityLabel.text = @"damn"; //it didn't worked...
My console prints
2017-04-19 10:47:58.849359+0800 string = Intensity is at 100
2017-04-19 10:47:58.849484+0800 label text = (null)
So what am I doing wrong? Why the label.text stays null?