隐藏/显示隐藏属性不起作用的UILabel

luc*_*uca -1 cocoa-touch objective-c uilabel

我在CustomViewController的方法viewDidLoad中实现了以下代码,根据我的需要打开/关闭标签可见性:

- (void)viewDidLoad
{
 [super viewDidLoad];

 myLabel.hidden=NO;

if (x==1) {

   myLabel.hidden=YES;//here is correctly hidden
}
else {
    [self.view bringSubviewToFront:myLabel];

    if(!myLabel.hidden){

      NSLog(@"I'm not hidden!");// the log displays correctly! so myLabel is not Hidden but I can't see it!
      [self.view bringSubviewToFront:myLabel];
    }
}
Run Code Online (Sandbox Code Playgroud)

MyLabel在CustomViewController.h("IBOutlet UILabel*myLabel;")中声明,并连接到Xib文件中对应的UILabel接口.

为什么即使它的"隐藏"属性是假的,我也看不到它?

Ps将UILabel文本分配给xib文件中的UILabel接口

谢谢卢卡

解决了感谢伙计们我觉得很愚蠢.标签已经不在舞台上所以我可以看到它.我只是重新定位它现在它工作正常

All*_*ian 6

你的代码中有一个拼写错误:你的出口似乎myLabel只是你的if陈述使用mylabel(应该是大写'L').还要注意,这个属性的getter isHidden并不hidden像你想象的那样(虽然这不是问题的根源,但Apple在他们的文档中说明了这一点,所以我认为值得一提).

编辑:

你说:

MyLabel在CustomViewController.h("IBOutlet UILabel*infoPostRist;")中声明,并连接到Xib文件中对应的UILabel接口.

那么,你不应该检查infoPostRist而不是myLabel那么吗?