Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UIVIEW控制器安全壳_Ios_Cocoa Touch_Ios5_Uiviewcontroller - Fatal编程技术网

Ios UIVIEW控制器安全壳

Ios UIVIEW控制器安全壳,ios,cocoa-touch,ios5,uiviewcontroller,Ios,Cocoa Touch,Ios5,Uiviewcontroller,我正在尝试在我的一个项目中使用UIViewController包含特性。该应用程序仅用于横向模式 我将UIViewControllerA添加为UIViewControllerB的子视图,并将A的主视图添加为其中一个B视图的子视图。我还在B中保存对a的引用: @interface BViewController : UIViewController @property (retain, nonatomic) AViewController *aVC; @end @implementation

我正在尝试在我的一个项目中使用UIViewController包含特性。该应用程序仅用于横向模式

我将UIViewControllerA添加为UIViewControllerB的子视图,并将A的主视图添加为其中一个B视图的子视图。我还在B中保存对a的引用:

@interface BViewController : UIViewController

@property (retain, nonatomic) AViewController *aVC;

@end

@implementation BViewController : UIViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.aVC = [self.storyBoard instantiateViewControllerWithIdentifier:@"A"];
    [self addChildViewController:self.aVC];
    [self.myContainerView addSubview:self.aVC.view];
}

@end
我的问题是,景观导向没有得到尊重。我做了一些调试并找到了一个解决方案,但我担心这并不理想,因为这更像是一种黑客行为:

在B中:

以一种方式:

我在这里遗漏了什么吗?

您的代码:

self.aVC = [self.storyBoard instantiateViewControllerWithIdentifier:@"A"];
[self addChildViewController:self.aVC];
[self.myContainerView addSubview:self.aVC.view];
他总是错的。将子控制器添加到父控制器后,必须将其发送到子控制器。请参见我的讨论:

至于旋转,很可能你只是做得太早了。当调用
viewDidLoad
时,应用程序以纵向启动,尚未旋转到横向。我在这里给出了这个问题的解决方案:

请注意,这里建议您等到
didRotateFromInterfaceOrientation:
完成视图外观的设置。我想你可能在这里面临着和我在那里描述的相同的问题

- (void)didMoveToParentViewController:(UIViewController *)parentVC
{
    // Interchange width and height
    self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.**height**, self.view.frame.size.**width**);
}
self.aVC = [self.storyBoard instantiateViewControllerWithIdentifier:@"A"];
[self addChildViewController:self.aVC];
[self.myContainerView addSubview:self.aVC.view];