presentViewController shows black page
You are not entering the nib name for the user Interface:
SuccessOrFailViewController *sfvc = [[SuccessOrFailViewController alloc] initWithNibName:@"SuccessOrFailViewController" bundle:nil];
[self presentViewController:sfvc animated:NO completion:NULL];
For storyboard this is the way to go:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
SuccessOrFailViewController *sfvc = [storyboard instantiateViewControllerWithIdentifier:@"SuccessOrFailViewController"];
[sfvc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:sfvc animated:YES];
swift _ Pushing ViewController in gives a black screen
It looks like MapViewController is designed in the storyboard. (If it were not, you would not be talking about @IBOutlet weak var map: MKMapView!
)
But if so, then saying MapViewController(coor: category.coordinates)
is not how to retrieve the instance that you designed in the storyboard. If you say that, you will indeed get basically an empty interface.
Instead, give that instance in the storyboard an identifier, and in your code, ask the storyboard to instantiate the view controller that has that identifier.
You will also have to rearrange your initialization completely. The storyboard is going to call init(coder:)
, not init(coor:)
. In fact, you can get rid of the latter entirely:
@IBOutlet weak var map: MKMapView!
var coor = [Double]()
required init?(coder: NSCoder) {
super.init(coder:coder)
}
override func viewDidLoad() {
super.viewDidLoad()
let lat = coor[0]
let long = coor[1]
print(lat)
print(long)
}
Now when you instantiate MapViewController from the storyboard, immediately also set mapView.coor
before pushing.
Black when screen when settings initial controller programmatically
The problem is that, in an attempt to make the project stop using the scene delegate and use the app delegate instead, you mangled the UIApplicationSceneManifest
entry in the Info.plist. Instead, you would need to delete that entry entirely. Its mere presence is what causes the scene delegate architecture to be used.
It would be better, however, to make this work for both iOS 12 using an app delegate and iOS 13 using a scene delegate (as I have described at https://stackoverflow.com/a/58405507/341994).
Pushing Viewcontroller through navigation controller , Showing Black screen
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let resultViewController = storyBoard.instantiateViewControllerWithIdentifier("ViewController") as! ViewController
self.navigationController?.pushViewController(resultViewController, animated: true)
Load Screen with from a View Controller
A couple of things are wrong here. It's okay, as SceneDelegate.swift was just added recently.
Your main issue here is that in your SceneDelegate's willConnectTo
your if let window = self.window
is nil, thus the rest of your code inside will not get executed resulting to a black screen.
In order to make Coordinator pattern work with storyboard in SceneDelegate.swift add these 2 properties and replace willConnectTo
to the following:
var coordinator: MainCoordinator?
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
let navController = UINavigationController() //create navController
coordinator = MainCoordinator(navigationController: navController) //initialize our coordinator
coordinator?.start() //start coordinator
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = navController //make it our root
window?.makeKeyAndVisible()
window?.windowScene = windowScene
}
Lastly, your AppDelegate.swift's didFinishLaunchingWithOptions
function body does not need anything but return true to implement Coordinator pattern
Feel free to use this as reference: https://github.com/SamuelFolledo/NewsApp/blob/646a005e1be9b90a4c63cb99bf92d5b2be6691cc/NewsApp/SceneDelegate.swift
iOS Black screen when close modally presented view controller
You can do it with UITabBarControllerDelegate
.
Option 1: Creating subclass of UITabBarController
class MyTabBar: UITabBarController, UITabBarControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
self.delegate = self
}
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
if let currentlySelectedViewController = self.viewControllers?[self.selectedIndex] as? YourThirdTabViewController,
let presentedViewController = currentlySelectedViewController.presentedViewController {
presentedViewController.dismiss(animated: false, completion: nil)
}
return true
}
}
Here I am assuming that I have my own sub class of UITabBarController
which is set as UITabBarControllerDelegate
using self.delegate = self
in view didLoad.
Option 2: Make TabBarController's ViewController UITabBarControllerDelegate
in their ViewDidLoad
If you dont wanna have your own subclass of UITabBarController
all you have to do is simply set your self as UITabBarControllerDelegate
in each ViewController
's ViewDidLoad
You can have a common protocol or extension to UIViewController
and confirm UITabBarControllerDelegate
to avoid code duplication if you decide to go down the path of not subclassing UITabBarController
protocol TabBarControllerProtocol: UITabBarControllerDelegate where Self: UIViewController {}
extension TabBarControllerProtocol {
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
if let currentlySelectedViewController = self.tabBarController?.viewControllers?[self.tabBarController?.selectedIndex ?? 0] as? SomeViewController,
let presentedViewController = currentlySelectedViewController.presentedViewController {
presentedViewController.dismiss(animated: false, completion: nil)
}
return true
}
}
In whichever ViewController, you want this logic to kick in you can say
class SomeViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.tabBarController?.delegate = self
}
}
extension SomeViewController: TabBarControllerProtocol {}
Thats it.
shouldSelect viewController
gets called every time user taps on tab to switch.
The if condition checks if ViewController
at selectedIndex (already selected not the new one) is viewController of specific interest or not and also checks if this view controller has presented anything or not, if it has presented it will call dismiss on it
This way when user switches tab from 3rd tab to any other tab, if third tab VC has presented another view controller modally it will dismiss it before it switches tab.
Related Topics
Confusing About @Environmentobject in Swiftui
How to Emit Items, One by One, from Collection with a Delay in Rxswift
Swift Short Syntax of Execution
Nsurlconnection Throws After Updating to Swift 2.0
How to Initialize a Struct with a Closure Parameter Like This
Preventing Nsurlsession Default Http Headers
Are Boolean Reads and Writes Guaranteed Atomic in Swift
Xcode Debugger Displays Incorrect Values for Variables
Vapor 3 Postgresql Crud Without Requests Http
Can You Strict Generic Types or Give One Parameter More Than One Type
How to Get Access Token from Instagram API
Calling Git Commands from Within a Swift Macos Application
How to Group Items in a Nspopupbutton
How to Use Axobserveraddnotification in Swift
Swiftui - Button - How to Pass a Function (With Parameters) Request to Parent from Child
In Swift 5, What Is a Way to Compare Pointers to Two Closures