Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash in Samples app on iPad #497

Merged
merged 2 commits into from
Sep 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ class DebugTableViewController: InspectableViewController {
}
}

func execute(for vc: DebugTableViewController) {
func execute(for vc: DebugTableViewController, sourceView: UIView) {
switch self {
case .animateScroll:
vc.animateScroll()
case .changeContentSize:
vc.changeContentSize()
vc.changeContentSize(sourceView: sourceView)
case .moveToFull:
vc.moveToFull()
case .moveToHalf:
Expand Down Expand Up @@ -165,8 +165,8 @@ class DebugTableViewController: InspectableViewController {

// MARK: - Actions

private func execute(command: Command) {
command.execute(for: self)
private func execute(command: Command, sourceView: UIView) {
command.execute(for: self, sourceView: sourceView)
}

@objc
Expand All @@ -177,7 +177,7 @@ class DebugTableViewController: InspectableViewController {
}

@objc
private func changeContentSize() {
private func changeContentSize(sourceView: UIView) {
let actionSheet = UIAlertController(title: "Change content size", message: "", preferredStyle: .actionSheet)
actionSheet.addAction(UIAlertAction(title: "Large", style: .default, handler: { (_) in
self.itemHeight = 66.0
Expand All @@ -201,6 +201,11 @@ class DebugTableViewController: InspectableViewController {
self.changeItems(3)
}))

if let popoverController = actionSheet.popoverPresentationController {
popoverController.sourceView = sourceView
popoverController.sourceRect = sourceView.bounds
}

self.present(actionSheet, animated: true, completion: nil)
}

Expand Down Expand Up @@ -250,7 +255,8 @@ extension DebugTableViewController: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("DebugTableViewController -- select row \(indexPath.row)")
guard let action = Command(rawValue: indexPath.row) else { return }
execute(command: action)
let cell = tableView.cellForRow(at: indexPath)
execute(command: action, sourceView: cell ?? tableView)
}

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
Expand Down