Reputation: 1
I have a label in my storyboard, i am setting text to my label in viewDidLoad
, but when i call my method, label is not updating. I am calling my method1 when my scrollview is scrolling.
Here is my code example;
//.h
NSString *text;
//.m
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
[self method1];
}
-(void) method1{
text = @"Here is the text";
NSRunLoop *runloop = [NSRunLoop currentRunLoop];
NSTimer *timer = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(updateLabel) userInfo:nil repeats:YES];
[runloop addTimer:timer forMode:NSRunLoopCommonModes];
[runloop addTimer:timer forMode:UITrackingRunLoopMode];
}
-(void) updateLabel{
label.text = text;
}
What should i do for updating my label? Thanks.
Upvotes: 0
Views: 3193
Reputation: 411
You need to control-drag your label object to your implementation (viewControllerClass.m) file using the Counterparts split pane view in Xcode, and you should give it a meaningful name ('label' alone is quite vague).
Then you can set the text using:
someLabel.text = @"some text";
Then you can try setting the text by using a declared NSString variable:
NSString *labelText = @"some text";
someLabel.text = labelText;
If this doesn't work, go back to IB and open the Utilities pane. Show the connections inspector (far right) to confirm it has the correct referencing outlet (someLabel - viewControllerClass). You might have wired it up twice, accidentally.
Upvotes: 2