我在viewDidLoad方法中初始化了一个UIButton:
- (void)viewDidLoad
{
[super viewDidLoad];
resumeButtonTest = [UIButton buttonWithType:UIButtonTypeCustom];
resumeButtonTest = [[UIButton alloc]initWithFrame:CGRectMake(500, 512, 48, 51)];
resumeButtonTest.frame = CGRectMake(500, 512, 48, 51);
[resumeButtonTest setImage:[UIImage imageNamed:@"resumebutton_splash_passive.png"] forState:UIControlStateNormal];
[resumeButtonTest setImage:[UIImage imageNamed:@"resumebutton_splash_ontouch.png"] forState:UIControlStateHighlighted];
refreshButtonTest = [UIButton buttonWithType:UIButtonTypeCustom];
refreshButtonTest = [[UIButton alloc]initWithFrame:CGRectMake(500, 600, 48, 51)];
refreshButtonTest.frame = CGRectMake(500, 600, 48, 51);
[refreshButtonTest setImage:[UIImage imageNamed:@"refreshbutton_splash_passive.png"] forState:UIControlStateNormal];
[refreshButtonTest setImage:[UIImage imageNamed:@"refreshbutton_splash_ontouch.png"] forState:UIControlStateHighlighted];
[self.view addSubview:resumeButtonTest];
[self.view addSubview:refreshButtonTest];
refreshButtonTest.hidden = TRUE;
resumeButtonTest.hidden =TRUE;
}
我设置为隐藏,直到下载失败,并且当它执行时此方法被调用:
-(void)displayFailure{
refreshButtonTest.hidden = FALSE;
resumeButtonTest.hidden = FALSE;
}
当代码执行时,按钮应该出现,但不是。 'hidden'命令无效。我需要刷新视图吗?我真的不明白发生了什么。这应该很简单但不是......
答案 0 :(得分:2)
问题在于我们将许多UIViews放在一起,所以当我试图隐藏和显示按钮时,隐藏或显示这些按钮的视图只是隐藏在另一个视图后面......所以始终检查您创建的视图数量,只在一个位置创建一次。
我们在找到解决方案之前检查的其他可能错误与线程有关。如果您在视图中隐藏按钮而您不在主线程上,则在该线程已加入主线程之前,UI不会更新。所以请检查一下这样:
if ([NSThread isMainThread])
NSLog(@"We are on main thread");
else
NSLog(@"Not on main thread, make sure you are if you want to do UI updates");
答案 1 :(得分:1)
通常在定义任何布尔变量时使用False和True。在UI c属性的Objective c中,我们总是使用YES或NO而不是True或False。因此,使用YES和NO代替True或False