在我的iOS应用程序中,我试图在另一个视图中设置UILabel的文本。无法以编程方式设置UILabel文本
我通过NSNotification传递给viewController,当它应该更新。我知道它正在接收消息,因为我记录了该消息,但它并未出现在UILabel中(我在故事板中添加了该消息)。
这是我的代码:
ProcessingViewController.h
@property (weak, nonatomic) IBOutlet UILabel *progressMessage;
ProcessingViewController.m
- (void)viewDidLoad {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateProgressDialog:) name:@"uploadProgress" object:nil];
}
-(void) updateProgressDialog: (NSNotification *) notification{
NSString *message = [notification object];
NSLog(@"received updateProgressDialog message of %@", message);
self.progressMessage.text = message;
[self.progressMessage setNeedsDisplay];
}
我的故事板:
是'IBOutlet'勾搭上了?也就是'progressMessage'非''nil'?如果'nil',如果'IBOutlet'没有连接到Interface Builder或视图控制器本身被错误实例化(例如'[[ProcessingViewController alloc] init]'而不是'[self.storyboard instantiateViewControllerWithIdentifier' :...]')。 – Rob
@Rob是和是。我可以记录progressMessage并确认它不是零。此外,我使用故事板连接IBOutlet。我添加了一张图片来展示我如何连接IBOutlet。 – scientiffic
然后确认'progressMessage'的'frame'。确保它的宽度足以显示文字。您可能需要查看整个视图层次结构,以确保框架正确,并且在标签前没有任何内容,从而遮盖它。例如,暂停执行并在'(lldb)'提示符下键入'po [[UIWindow keyWindow] recursiveDescription]'。你也可以尝试内置在Xcode中的有点片状的视图调试器。 – Rob