difference between presentViewController and UINavigationController?

presentViewController offers a mechanism to display a so-called modal view controller; i.e., a view controller that will take full control of your UI by being superimposed on top of a presenting controller. UINavigationController offers a much more flexible mechanism where you can push a new controller, and later pop it, so to go back to … Read more

UIViewControllerHierarchyInconsistency when trying to present a modal view controller

This happened to me already twice in the newest Xcode release. In both cases I needed to make changes to the UIViewController’s XIB file (In you case it would be MapViewController.xib: BEFORE: Move main View out of View Controller’s children: Remove View Controller from the XIB (it is not necessary since File’s Owner should be … Read more

Whats the programmatic opposite of showViewController:sender:

There is a chapter on how showViewController:sender: and showDetailViewController:sender: work in Programming iOS 8: Dive Deep into Views, View Controllers, and Frameworks. When these methods are called, they call targetViewControllerForAction:sender: on themselves and call this method on the returned object. The target object can then display the view controller in an appropriate way. For example, … Read more

iOS: present view controller programmatically

If you’re using a storyboard, you probably shouldn’t be using alloc and init to create a new view controller. Instead, look at your storyboard and find the segue that you want to perform; it should have a unique identifier (and if not, you can set one in the right sidebar). Once you’ve found the identifier … 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

UILabel updating stops during scrolling UIScrollView

I had recently the same trouble and found the solution here: My custom UI elements…. In short: while your UIScrollView is scrolling, the NSTimer is not updated because the run loops run in a different mode (NSRunLoopCommonModes, mode used for tracking events). The solution is adding your timer to the NSRunLoopModes just after creation: NSTimer … Read more

Unable to hide the navigationBar when embedding SwiftUI in UIKit

UIHostingViewController respects the navigationBarHidden value of your SwiftUI view. You can either call .navigationBarHidden(true) at the end of your SwiftUI view, or you can use the custom UIHostingController subclass shown in the example below. Solution: import SwiftUI import UIKit class YourHostingController <Content>: UIHostingController<AnyView> where Content : View { public init(shouldShowNavigationBar: Bool, rootView: Content) { super.init(rootView: … Read more