2

I have a UIViewController named LoginViewController, and it is a rootViewController in the AppDelegate. In the LoginViewController, I have two buttons: Login and Enroll.

When I tap Login, I assign a TabBarController as the rootViewController, then show the TabBarController. However, now I think I need to add another UIViewcController as a subview when I tap Enroll. I tried the following:

[self.view addsubview:viewcontroller.view];

But the problem here is My ViewController's view.top is pinned about 20 pixels below the top of the screen. I think there is an issue with the status bar, but I can't figure out how to fix it.

I think that I need to add my ViewController as a subview to the LoginViewController, then redirect from there to different views. Can someone please suggest other options?

jungledev
  • 4,195
  • 1
  • 37
  • 52
Pradeep Reddy Kypa
  • 3,992
  • 7
  • 57
  • 75

3 Answers3

2

Try to set frame to your enroll screen object then add it as a subview to loginview. Ex:

[enrollViewcontroller.view setFrame:CGRectMake(0,0,320,440)];
[self.view addsubview:enrollViewcontroller.view];
Dee
  • 1,887
  • 19
  • 47
  • 1
    change the frame according to your requirement. Because it is 20 pixel down try to change the y axis position like this CGRectMake(0,-20,320,440) and check. – Dee Jun 18 '12 at 18:08
1

You should not make a UIViewController a subview of another UIViewController's view. What you likely want to do if treat the subview as a normal UIView (if not both of those views) so that you only have one UIViewController on screen and it occupies the entire screen.

More here: How to add an UIViewController's view as subview

Community
  • 1
  • 1
eternalmatt
  • 3,524
  • 4
  • 25
  • 25
0

Instead of adding a UIViewController as a subview to another UIViewController, I have decided to present my ViewController as a ModalViewController using

[self presentModalViewController:myViewController animated:YES];
Pradeep Reddy Kypa
  • 3,992
  • 7
  • 57
  • 75