Rotation only in one ViewController

I’d recommend using supportedInterfaceOrientationsForWindow in your appDelegate to allow rotation only in that specific view controller, ex: Swift 4/Swift 5 func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { // Make sure the root controller has been set // (won’t initially be set when the app is launched) if let navigationController = window?.rootViewController as? … Read more

Switching ViewControllers with UISegmentedControl in iOS5

This code works pretty well for your purpose, I use it for one of my new apps. It uses the new UIViewController containment APIs that allow UIViewControllers inside your own UIViewControllers without the hassles of manually forwarding stuff like viewDidAppear: – (void)viewDidLoad { [super viewDidLoad]; // add viewController so you can switch them later. UIViewController … Read more

How can I switch views programmatically in a view controller? (Xcode, iPhone)

If you’re in a Navigation Controller: ViewController *viewController = [[ViewController alloc] init]; [self.navigationController pushViewController:viewController animated:YES]; or if you just want to present a new view: ViewController *viewController = [[ViewController alloc] init]; [self presentViewController:viewController animated:YES completion:nil];

In SwiftUI, how to use UIHostingController inside an UIView or as an UIView?

View controllers are not just for the top level scene. We often place view controllers within view controllers. It’s called “view controller containment” and/or “child view controllers”. (BTW, view controller containers are, in general, a great way to fight view controller bloat in traditional UIKit apps, breaking complicated scenes into multiple view controllers.) So, Go … Read more

When should I initialize a view controller using initWithNibName?

-initWithNibName:bundle: is the designated initializer for UIViewController. Something should eventually call it. That said, and despite Apple’s examples (which favor brevity over maintainability in many cases), it should never be called from outside the view controller itself. You will often see code like this: MYViewController *vc = [[MYViewController alloc] initWithNibName:@”Myview” bundle:nil]; I say this is … Read more