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?

3 Answers 3

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];
Sign up to request clarification or add additional context in comments.

1 Comment

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.
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

Comments

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];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.