UILabel第一次不会更新
我有一个模态视图,其中仅包含 o 按钮和 uilabel。
按钮关闭模态 v:
- (IBAction) close {
[self dismissModalViewControllerAnimated:YES];
}
现在,我创建了这个视图:
nw = [[NewsViewController alloc] initWithNibName:@"NewsViewController" bundle:nil];
nw.modalInPopover = YES;
nw.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[nw setValues:@"asdasd"];
[self presentModalViewController:nw animated:YES];
一切正常。
它加载正确,但 uilabel 值没有显示正确的文本标签。
怎么可能?
第二次单击,值设置正确...
这是setValues func:
- (void) setValues:(NSString*)val {
[firstLabel setText:val];
}
调试,它第一次显示UILabel 0x0...这是一个问题,但第二次它正确创建并且值设置。
有什么办法解决吗?
阿尔贝托.
i have a modal view which contains only o button and a uilabel.
The button close the modal v:
- (IBAction) close {
[self dismissModalViewControllerAnimated:YES];
}
Now, i create this view:
nw = [[NewsViewController alloc] initWithNibName:@"NewsViewController" bundle:nil];
nw.modalInPopover = YES;
nw.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[nw setValues:@"asdasd"];
[self presentModalViewController:nw animated:YES];
all ok.
It loads correctly but the uilabel value don't show me the correct text label.
How it's possible?
Second time click, the value was setted correctly...
This is setValues func:
- (void) setValues:(NSString*)val {
[firstLabel setText:val];
}
Debugging, it show first time UILabel 0x0... this is a problem, but second time it's created correctly and the value is setted.
any idea to fix?
alberto.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可能您在 viewDidLoad 中设置了标签文本,直到视图完成自身加载。
尝试放入
viewDidAppear
或viewWillAppear
代替。Probably you set label text in
viewDidLoad
, until view had finished loading itself.Try put in
viewDidAppear
orviewWillAppear
instead.第一次调用 setValues 时,
NewsViewController
可能尚未加载其视图。要进行确认,请在[ns setValues:@"asdasd"];
之前和NewsViewController
的-[viewDidLoad]
方法中设置断点。要解决此问题,您可以为
NewsViewController
中的文本添加一个实例变量。然后在-[setValues:]
中设置实例变量,并在该实例变量的-[viewDidLoad]
方法中设置标签的文本。On your first call to setValues,
NewsViewController
probably hasn't yet loaded its view. To confirm, set a breakpoint before[ns setValues:@"asdasd"];
and in the-[viewDidLoad]
method ofNewsViewController
.To work around this, you could add an instance variable for the text in
NewsViewController
. Then set the instance variable in-[setValues:]
and set the label's text in its-[viewDidLoad]
method from that instance variable.您还可以在主线程上设置文本
You could also set text on the main thread