在 Init 上隐藏 UILabel
我对这个基本代码有疑问:
-(id)init{
self = [super init];
if(self){
self.mensaje = [[UILabel alloc]initWithFrame:CGRectMake(100.0, 100.0, 100.0, 100.0)];
[self.mensaje setText:@"He vuelto"];
[self.view addSubview:self.mensaje];
[self.mensaje setHidden:YES];
}
return self;
}
除了 [self.mensaje setHidden:YES];
之外,所有代码都工作正常。标签始终在开始时显示。
我希望能帮助我,这是基本的,但必要的!
祝你好运!
I'm having a problem with this basic code:
-(id)init{
self = [super init];
if(self){
self.mensaje = [[UILabel alloc]initWithFrame:CGRectMake(100.0, 100.0, 100.0, 100.0)];
[self.mensaje setText:@"He vuelto"];
[self.view addSubview:self.mensaje];
[self.mensaje setHidden:YES];
}
return self;
}
All the code works fine, except [self.mensaje setHidden:YES];
. The Label is always shown at start.
I hope could help me, this is basic, but necessary!!
Good luck!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这段代码放错了地方。您不应该在视图控制器的初始化程序中创建和使用视图(假设上述代码位于视图控制器类内部)。
相反,请执行以下操作:
这还假设您正在使用 ARC。如果没有,则需要添加
autorelease
,如下:This code is in the wrong place. You shouldn't be creating and working with views in the initializer of a view controller (assuming the above code is inside a view controller class).
instead, do the following:
This also assumes you are using ARC. If not, you need to add
autorelease
as follows: