我有两个tabbars上下,当我点击tabbaritem UIView show时,但是当我点击另一个tabbar项时,前一个视图仍然保留在控制器中。代码是
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
switch (item.tag) {
case 0:
{
NSLog(@"home");
homeViewController *homeVc= [[homeViewController alloc] initWithNibName:@"homeViewController" bundle:nil];
[self.view insertSubview:homeVc.view belowSubview:tabBar];
break;
}
case 1:
{
NSLog(@"compus");
compusViewController *compusVc= [[compusViewController alloc] initWithNibName:@"compusViewController" bundle:nil];
[self.view insertSubview:compusVc.view belowSubview:tabBar];
break;
}
答案 0 :(得分:0)
没有直接的方法可以简单地删除所有子视图。您必须为所有子视图调用removeFromSuperview。幸运的是,代码简洁明了。使用[self.containerView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)]。 - Sikhapol Saijit