iOS13で導入されたContext Menusを使ってプレビューを表示します。
プレビューをタップすると詳細画面に遷移します。
問題
正確に調べていないのでアレですが、
少なくともiOS13 beta6からプレビューをタップしても詳細画面に遷移しなくなりました。
原因
動いていた当時は
UITableViewDelegate
func tableView(_ tableView: UITableView,
willCommitMenuWithAnimator animator: UIContextMenuInteractionCommitAnimating)
プレビューをタップするとこれが呼ばれていましたが、
少なくともiOS13 beta6からは
UITableViewDelegate
func tableView(_ tableView: UITableView,
willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration,
animator: UIContextMenuInteractionCommitAnimating)
プレビューをタップするとこちらが呼ばれるようになりました。
Appleのドキュメントを見ても何も書いてありません。
久々に見たら書いてありました。
こちらのサイトを見るとiOS13 beta6でAPIが追加になってますね。
iOS13 Beta 5 to Beta6 API Differences
トリビア
プレビュー画面から画面遷移する処理は以下のようになりますが、
UITableViewDelegate
func tableView(_ tableView: UITableView,
willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration,
animator: UIContextMenuInteractionCommitAnimating) {
animator.addCompletion {
// 画面遷移する処理
}
}
上記処理にanimator.preferredCommitStyle
を追加すると画面遷移するときの動きが選択できます。
// プレビュー画面から直接画面遷移する。(デフォルト)
animator.preferredCommitStyle = .pop
// 一度元の画面に戻ってから画面遷移する。
animator.preferredCommitStyle = .dismiss
Apple Developer Forumを見たところ、iOS13 beta6からの現象らしいので訂正します。
iOS13 beta8 + Xcode11 beta6に基づいて記述しています。
リリース版では変更される可能性があります。