2012-06-18 123 views
2

我有一个UIViewController,名为LoginViewController,它是AppDelegate中的rootViewController。在LoginViewController中,我有两个按钮:LoginEnroll如何将UIViewController作为子视图添加到UIViewController(RootViewController)?

当我点击Login时,我指定TabBarController作为rootViewController,然后显示TabBarController。不过,现在我想我需要添加另一个UIViewcController作为子视图,当我点击Enroll。我试过如下:

[self.view addsubview:viewcontroller.view]; 

但这里的问题是屏幕下方顶部20像素左右我的ViewController的view.top被固定。我认为状态栏有问题,但我无法弄清楚如何解决它。

我认为我需要将我的ViewController作为子视图添加到LoginViewController,然后从那里重定向到不同的视图。有人可以建议其他选项吗?

回答

1

你不应该让一个UIViewController另一UIViewController的视图的子视图。如果将子视图视为普通UIView(如果不是这两个视图),那么您可能想要执行的操作,以便在屏幕上只有一个UIViewController,并占用整个屏幕。

这里更多:How to add an UIViewController's view as subview

2

尝试将帧设置为您的注册屏幕对象,然后将其作为子视图添加到loginview。 例如:

[enrollViewcontroller.view setFrame:CGRectMake(0,0,320,440)]; 
[self.view addsubview:enrollViewcontroller.view]; 
+1

变化根据您的要求的框架。因为它下降了20个像素,所以尝试像这样改变y轴位置CGRectMake(0,-20,320,440)并检查。 – Dee

+0

这是正确的方式来启动在-20坐标乌尔帧?连我都不知道的 –

+0

。一旦它为我工作。所以建议你。 – Dee

0

而不是增加一个UIViewController作为一个子视图到另一个的UIViewController,我决定提出我的ViewController作为ModalViewController使用

[self presentModalViewController:myViewController animated:YES]; 
相关问题