Click here to Skip to main content
11,636,778 members (77,567 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: iOS
I would like to be able to update myViewController's UILabel called score from myClass embedded in myViewController.

In myClass I created a pointer to myViewCOntroller called parent. I assigned the view pointer in the init of myClass using:

MyAppDelegate * appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
self.parent = [appDelegate viewController];

I've forward declared the viewController in .h and imported to the the .m of myClass

When I get to the setLabel function in myClass, the parent pointer variable looks good, and so does the UILabel variable, and even the label's text but the label doesn't get updated after

NSString * text = [[NSString alloc] initWithFormat:@"Score, %d!", score];
 
parent.score.text = text;

Currently I'm creating the UILabel using the Interface Builder. I dragged from the control to the header file to create the variable and the preperty functions, and right-clicked on File's Owner to connect the control outlet to the variable.

I noticed that I can update the label form the viewController but not from myClass.

Any ideas of what I doing wrong?
Posted 12-Jun-12 19:14pm
Edited 12-Jun-12 19:16pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Can you please put your code where you are setting label? Actually i need to see it in detail. Secondly are you calling this code from some secondary thread?
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 jyo.net 263
1 stibee 249
2 Sergey Alexandrovich Kryukov 229
3 Suvendu Shekhar Giri 225
4 OriginalGriff 183
0 OriginalGriff 8,941
1 Sergey Alexandrovich Kryukov 8,493
2 Mika Wendelius 6,909
3 F-ES Sitecore 2,388
4 Suvendu Shekhar Giri 2,320


Advertise | Privacy | Mobile
Web04 | 2.8.150728.1 | Last Updated 29 Jun 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100