ice-bit / DineUI

Building a UI app for a previous console project; the core functionality is restaurant management. Check the URL below 👇 for console app!
https://github.com/sek-r0/Dine
0 stars 0 forks source link

Fix UIAlertController presentation issue on iPad #4

Closed ice-bit closed 4 months ago

ice-bit commented 4 months ago

Summary

This pull request fixes the issue where a UIAlertController of style UIAlertControllerStyleActionSheet would cause an error when presented on an iPad due to missing popover presentation information.

Changes

Code Example


// Create the alert controller
let alertController = UIAlertController(title: "Title", message: "Message", preferredStyle: .actionSheet)

// Add an action
let action = UIAlertAction(title: "Action", style: .default) { _ in
    // Handle action
}
alertController.addAction(action)

// Configure popover presentation for iPad
if let popoverController = alertController.popoverPresentationController {
    popoverController.sourceView = self.view // Specify the view from which the popover should originate
    popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0) // Set the rectangle for the popover
    popoverController.permittedArrowDirections = [] // Optional: specify allowed arrow directions
}

// Present the alert controller
self.present(alertController, animated: true, completion: nil)