我在viewController中有两个视图。我不想为他们使用两个xib文件。我想在单个xib中使用它们。现在我想根据条件显示出来。例如,如果条件正确,那么我想显示第一个视图,否则显示第二个视图。我不知道该怎么做?
我通过这种方式添加第二个视图,但它没有显示:
-(void)viewWillAppear:(BOOL)animated{
if([[[NSUserDefaults standardUserDefaults] valueForKey:@"service-provider"] boolValue]==1){
[[MyAppDelegate.tabBar.tabBar.items objectAtIndex:1] setTitle:@"History"];
self.title = @"History";
self.view.hidden=YES;
self.ServiceProviderView.hidden=NO;
[self.ServiceProviderView addSubview:historyTable];
}
else{
[[MyAppDelegate.tabBar.tabBar.items objectAtIndex:1] setTitle:@"Search"];
self.title = @"Search";
self.view.hidden=NO;
self.ServiceProviderView.hidden=YES;
[self.view setUserInteractionEnabled:YES];
searchLbl.font=[UIFont fontWithName:GZFont size:18.0f];
headingLbl.font=[UIFont fontWithName:@"Garamond 3 SC" size:20.0f];
NSMutableAttributedString *gpsSearch = [[NSMutableAttributedString alloc] initWithString:@"GPS Search"];
[gpsSearch addAttribute:(NSString*)kCTUnderlineStyleAttributeName
value:[NSNumber numberWithInt:NSUnderlineStyleSingle]
range:(NSRange){0,[gpsSearch length]}];
self.headingLbl.attributedText = gpsSearch;
self.headingLbl.textColor = [UIColor blackColor];
btn_Favorite.titleLabel.font=[UIFont fontWithName:GZFont size:18.0f];
btn_inviteUser.titleLabel.font=[UIFont fontWithName:GZFont size:18.0f];
btn_locateNearBy.titleLabel.font=[UIFont fontWithName:GZFont size:18.0f];
btn_scanBarCode.titleLabel.font=[UIFont fontWithName:GZFont size:18.0f];
txtSearchUsername.font=[UIFont fontWithName:GZFont size:15.0f];
txtSearchEstablishment.font=[UIFont fontWithName:GZFont size:15.0f];
}
}
如果满足第一个条件,那么serviceProviderView不会显示。我已经在xib中添加了这个视图。
答案 0 :(得分:0)
为这两个视图创建引用IBOutlets。使用这些引用隐藏或显示它们。
if(<condition>)
{
firstView.hidden = YES;
}
else
{
secondView.hidden = NO;
}