使用指向viewController的指针更新UILabel时遇到问题 [英] Trouble Updating UILabel with pointer to viewController

查看:105
本文介绍了使用指向viewController的指针更新UILabel时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够从myViewController中嵌入的myClass中更新myViewController的UILabel,称为score.

在myClass中,我创建了一个指向myViewCOntroller的指针,称为parent.我使用以下方法在myClass的init中分配了视图指针:

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];



我已经在.h中声明了viewController,并导入到myClass的.m中

当我进入myClass中的setLabel函数时,父指针变量看起来不错,UILabel变量甚至标签文本也是如此,但是标签在更新后没有更新



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;



目前,我正在使用Interface Builder创建UILabel.我从控件拖到头文件以创建变量和preperty函数,然后右键单击File的Owner以将控件出口连接到变量.

我注意到我可以从viewController更新标签,但不能从myClass更新标签.

任何关于我做错事情的想法吗?



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?

推荐答案

能否将您的代码放在设置标签的地方?实际上,我需要详细了解它.其次,您是从某个辅助线程调用此代码的吗?
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?


这篇关于使用指向viewController的指针更新UILabel时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆