我在类别表格视图中使用自定义标题。所以,根据那个条件,我必须隐藏标题和它的细节。因此,我使用以下代码来显示带有条件的标题。
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *aView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)];
if(section==0)
{
if(![appDelegate.purchase_requisitions_preference isEqualToString:@"0"] && ![appDelegate.purchase_requisitions_preference isEqualToString:@"null"])
{
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(0, 0, 320, 30)];
btn.backgroundColor = [UIColor colorWithRed:39.0/255.0 green:131.0/255.0 blue:33.0/255.0 alpha:1.0f];
[btn setTag:section+1];
UILabel *label1 = [[UILabel alloc]init];
label1.frame = CGRectMake(20, 0, 320, 30);
label1.backgroundColor = [UIColor clearColor];
label1.textColor = [UIColor whiteColor];
label1.font = [UIFont boldSystemFontOfSize:16];
label1.text = @"Purchase Order Requisitions";
[label1 setTag:section+1];
[btn addSubview:label1];
[aView addSubview:btn];
[btn addTarget:self action:@selector(sectionTapped:) forControlEvents:UIControlEventTouchDown];
}
else
{
return nil;
}
}
else if(section==1)
{
if(![appDelegate.hr_vacancies_preference isEqualToString:@"0"] && ![appDelegate.hr_vacancies_preference isEqualToString:@"null"])
{
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(0, 0, 320, 30)];
btn.backgroundColor = [UIColor colorWithRed:39.0/255.0 green:131.0/255.0 blue:33.0/255.0 alpha:1.0f];
[btn setTag:section+1];
UILabel *label1 = [[UILabel alloc]init];
label1.frame = CGRectMake(20, 0, 320, 30);
label1.backgroundColor = [UIColor clearColor];
label1.textColor = [UIColor whiteColor];
label1.font = [UIFont boldSystemFontOfSize:16];
label1.text = @"Human Resource Vacancies";
[label1 setTag:section+1];
[btn addSubview:label1];
[aView addSubview:btn];
[btn addTarget:self action:@selector(sectionTapped:) forControlEvents:UIControlEventTouchDown];
}
else
{
return nil;
}
}
else if(section==2)
{
if(![appDelegate.hr_offers_preference isEqualToString:@"0"] && ![appDelegate.hr_offers_preference isEqualToString:@"null"])
{
NSLog(@"in offer");
UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
[btn setFrame:CGRectMake(0, 0, 320, 30)];
btn.backgroundColor = [UIColor colorWithRed:39.0/255.0 green:131.0/255.0 blue:33.0/255.0 alpha:1.0f];
[btn setTag:section+1];
UILabel *label1 = [[UILabel alloc]init];
label1.frame = CGRectMake(20, 0, 320, 30);
label1.backgroundColor = [UIColor clearColor];
label1.textColor = [UIColor whiteColor];
label1.font = [UIFont boldSystemFontOfSize:16];
label1.text = @"Human Resource Job Offers";
[label1 setTag:section+1];
[btn addSubview:label1];
[aView addSubview:btn];
[btn addTarget:self action:@selector(sectionTapped:) forControlEvents:UIControlEventTouchDown];
}
else
{
return nil;
}
}
return aView;
}
如果我的条件是假的,那么我想隐藏我的标题以及它的细节。它的细节正在隐藏,但标题仍然显示在那里。