Click here to Skip to main content
12,954,403 members (60,229 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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
Updated 12-Jun-12 19:16pm

1 solution

Rate this: bad
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?

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,524
CHill60 3,490
Maciej Los 3,123
ppolymorphe 2,030
Jochen Arndt 1,975

Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 29 Jun 2012
Copyright © CodeProject, 1999-2017
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