Reputation: 61
I have intialised a UIButton in the viewDidLoad method:
- (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;
}
That I set to hidden until such a time that a download fails, and when it does this method gets called:
-(void)displayFailure{
refreshButtonTest.hidden = FALSE;
resumeButtonTest.hidden = FALSE;
}
and when the code is executed the buttons should appear, but the don't. The 'hidden' command has no effect. Do I need to refresh the view? I really don't understand what is going on. This should be really simple but it isn't...
Upvotes: 0
Views: 1225
Reputation: 61
The problem was that we were putting many UIViews over one another, so when I was trying to hide and show the buttons, the view on which these buttons were being hidden or shown was simply hidden behind another view....so always check how many views you are creating, only create it once, in one place.
Other possible errors that we checked before finding the solution was to do with threading. If you are hiding buttons in a view and you aren't on the main thread, then the UI will not update until that thread has been joined to the main thread. So put a check in for that like this:
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");
Upvotes: 2
Reputation: 1805
Usually False and True are used when you are defining any Boolean variable. In Objective c for UI properties we always use YES or NO and not True or False. So use YES and NO in place of True or False
Upvotes: 1