我在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中添加了此视图。
发布于 2013-12-26 20:53:51
为这两个视图创建引用IBOutlets。使用这些引用来隐藏或显示它们。
if(<condition>)
{
firstView.hidden = YES;
}
else
{
secondView.hidden = NO;
}https://stackoverflow.com/questions/20785194
复制相似问题