I am new to iOS development, I have plain objective -c class "MoneyTimer.m" for running timer, from there i want to update the an UI label with the changing value of timer. I want to Know how to access the UI element from non UI thread ? I am Using Xcode 4.2 and storyboarding.
In blackberry simply by getting the event lock one can update the UI's from non UI thread.
//this the code from MyTimerClass
{...
if(nsTimerUp == nil){
nsTimerUp = [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(countUpH) userInfo:nil repeats: YES];
...}
(void) countUpH {
sumUp = sumUp + rateInSecH;
**//from here i want to update the UI label **
...
}
To change the font or the size of a UILabel in a Storyboard or . XIB file, open it in the interface builder. Select the label and then open up the Attribute Inspector (CMD + Option + 5). Select the button on the font box and then you can change your text size or font.
A view that displays one or more lines of informational text.
This is the quickest and simplest way to do it is:
- (void) countUpH{
sumUp = sumUp + rateInSecH;
//Accessing UI Thread
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
//Do any updates to your label here
yourLabel.text = newText;
}];
}
If you do it this way you don't have to switch to a different method.
Hope this helps.
Sam
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With