クイック アクションから特定のビュー コントローラーを開く方法です。特定のView Controllerを開くために、App Delegateに以下のコードがあります。私のアプリはスナップチャット アプリと同じデザインです。つまり、スクロール ビューに異なるビュー コントローラーが埋め込まれており、Sunday ビュー コントローラーなどの特定のビュー コントローラーをターゲットにしたいと考えています。
アイデアは、クイック アクション アイテムから選択された 1 番目、2 番目、または 3 番目のアイテムのいずれかを提示することです。
func handleShortCutItem(shortcutItem: UIApplicationShortcutItem) -> Bool {
var handled = false
guard ShortcutIdentifier(fullType: shortcutItem.type) != nil else {
return false
}
guard let shortcutType = shortcutItem.type as String? else {
return false
}
switch (shortcutType) {
case ShortcutIdentifier.First.type:
//Present the Add View Controller
handled = true
let mondayVC : MondayViewController = MondayViewController(nibName: "MondayViewController", bundle: nil)
self.window?.rootViewController?.presentViewController(mondayVC, animated: true, completion: nil)
break
case ShortcutIdentifier.Second.type:
//Present the View Controller related to this Screen
handled = true
let fridayVC : FridayViewController = FridayViewController(nibName: "FridayViewController", bundle: nil)
self.window?.rootViewController?.presentViewController(fridayVC, animated: true, completion: nil)
break
case ShortcutIdentifier.Third.type:
//Present the View Controller related to this Screen
handled = true
let sundayVC : SundayViewController = SundayViewController(nibName: "SundayViewController", bundle: nil)
self.window?.rootViewController?.presentViewController(sundayVC, animated: true, completion: nil)
break
default:
break
}
return handled
}
この関数を実行するデリゲートの追加コードは次のとおりです。
func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
let handledShortcutItem = self.handleShortCutItem(shortcutItem)
completionHandler(handledShortcutItem)
}