I want to hide an button if my array is not nil using the following code however, for some reason it is not working. I cannot see any mistakes in my code.. Please help me.. Thanks..
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
NSString *title = nil;
HowtoUseButton = [[[CustomButton alloc] init] autorelease];
[HowtoUseButton addTarget:self action:@selector(openLink) forControlEvents:UIControlEventTouchDown];
HowtoUseButton.frame = CGRectMake(80.0, 140.0, 160.0, 70.0);
[self.view addSubview:HowtoUseButton];
if (document.count > 0){
HowtoUseButton.hidden = YES; // not working
title = Title_Doc;
}
else if (self.documentURLs.count == 0){
title = Title_No_Doc;
HowtoUseButton.hidden = NO;
}
return title;
}
Since you are using this in
titleForHeaderInSection, it is probably being called more than once. And if that is the case, perhaps only some of the buttons are hidden.Try changing:
to:
Also, as the other people who have already answered have said, this really shouldn’t here in the first place. Create the button in interface builder, or in
viewDidLoadonce, and simply set the hidden property where you need to change it.