How to add a UIViewController as a subview to a UIViewController(RootViewController)?
Solution 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
Solution 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];
Pradeep Reddy Kypa
iOS Architect with a relevant experience of 13+ years. I want to master iOS SDK Technologies and very much interested to learn any new stuff regarding iOS.#SOreadytohelp
Updated on June 04, 2022Comments
-
Pradeep Reddy Kypa almost 2 years
I have a
UIViewController
namedLoginViewController
, and it is arootViewController
in theAppDelegate
. In theLoginViewController
, I have two buttons:Login
andEnroll
.When I tap
Login
, I assign aTabBarController
as therootViewController
, then show theTabBarController
. However, now I think I need to add anotherUIViewcController
as a subview when I tapEnroll
. 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?
-
Dee almost 12 yearschange 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.