iOS:从辅助XIB返回到主XIB

我正在尝试在第二个XIB后改回主xib。 这是我正在使用的当前代码:

NSArray *nibObjs = [[NSBundle mainBundle] loadNibNamed:@"Results1" owner:self options:nil]; UIView *aView = [nibObjs objectAtIndex:0]; self.view = aView; 

在第二个xib上有一个返回到原始xib的button。 当我点击button的应用程序崩溃。 我不知道为什么,因为它不显示错误 – 它只是崩溃。 以下是第二个xib或“Results1”xib文件上的button上的代码:

 -(IBAction)Button100:(id)sender { NSArray *nibObjs = [[NSBundle mainBundle] loadNibNamed:@"main" owner:self options:nil]; UIView *aView = [nibObjs objectAtIndex:0]; self.view = aView; } 

不知道我在做什么错。

添加作为子视图,所以你可以只是'popup'结果1视图closures:

 // in your .h @property (strong) UIView *aView; // replace your provided code with this NSArray *nibObjs = [[NSBundle mainBundle] loadNibNamed:@"Results1" owner:self options:nil]; self.aView = [nibObjs objectAtIndex:0]; [self.view addSubview:self.aView]; - (IBAction)Button100:(id)sender { [self.aView removeFromSuperview]; self.aView = nil; } 

只是一个build议 – 如果你想让他们“交换”,考虑在UIView中使用类方法transitionFromView:toView:duration:options:completion:

问题是我需要closures自动引用计数。