I'm trying to change though a timer in a different method the text of a label I created programmatically in a UIView overlay that goes on a UIImagePickerviewController, but of course when I try to change the text in this way
labelname.text = @"TEST";
I get the error "use of undeclared identifier labelname
"
How can I refer to that specific label? Should I create a new label each time the timer ticks?
I tried to declare it in the .h file, but I'm guessing i'm just creating a different label...any ideas?
Just Pass the Label As a whole to the Timer Function:
Say Your Label is defined in ViewDidLoad like this :
- (void)viewDidLoad
{
//Do Something here
UILabel * label = [[UILabel alloc]
initWithFrame:CGRectMake(xcoordinateLabel, ycoordinateLabel, width, height)];
label.backgroundColor = [UIColor clearColor];
label.textAlignment = UITextAlignmentCenter;
label.textColor=[UIColor whiteColor];
label.text = @"TEST";
[self.view addSubview:label];
[self changeLabelText:label];
}
Where your changeLabelText is defined as this with some delay:
- (void) changeLabelText:(UILabel *)label
{
//Changing Values after 10s Delay
double delayInSeconds = 10.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW,
(int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
label.text = @"TESTING Change";
});
}
Your Timer function can replace changeLabelText