iOS:从辅助XIB返回主XIB

时间:2012-08-10 00:36:58

标签: objective-c ios xib

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

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

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

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

不确定我做错了什么。

2 个答案:

答案 0 :(得分:0)

添加为子视图,这样您就可以“关闭”Results1视图:

// 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;
}

只是一个建议 - 如果你想让它们'交换',请考虑在UIView中使用类方法transitionFromView:toView:duration:options:completion:

答案 1 :(得分:0)

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

相关问题