xib没有连接到控制器?

时间:2011-09-15 15:26:31

标签: iphone objective-c view uiviewcontroller xib

我对iPhone开发非常陌生,所以请原谅这篇文章,如果它看起来很幼稚。我想简单地将子视图添加到我当前的视图中(如果这是在iPhone上打开新屏幕的最佳方式)。这是我的代码:

QuickCalcController *aViewController = [[QuickCalcController alloc]
                                       initWithNibName:@"QuickCalcController" bundle:nil];

aViewController.view.frame = CGRectMake(0, 100, quickCalcController.view.frame.size.width, quickCalcController.view.frame.size.height);  
[self.view addSubview: quickCalcController.view];
self.view.bounds = quickCalcController.view.bounds;

问题是,当调用此代码时,显示的视图不是QuickCalcController.xib。它是MainView.xib。文件的所有者是QuickCalcController ...我错过了什么吗?

提前致谢。

1 个答案:

答案 0 :(得分:2)

你应该让mainViewController呈现QuickCalcController:

QuickCalcController *aViewController = [[QuickCalcController alloc]
                                       initWithNibName:@"QuickCalcController" bundle:nil];
[self presentModalViewController:aViewController animated:YES];
[aViewController release], aViewController = nil;

然后dimiss QuickCalcController只需在QuickCalcController中调用[self dismissModalViewControllerAnimated:YES];