我的应用程序的条目ViewController包含两个按钮:weight和age。在 mainViewController中,这是单击weight按钮时运行的代码:
@IBAction func weightSearch(_ sender: Any) {
//Weight button clicked
inputReset()
userInput.keyboardType = UIKeyboardType.numberPad
userInput.becomeFirstResponder()
}
这是单击age按钮时运行的代码:
@IBAction func ageSearch(_ sender: Any) {
//Age button clicked
inputReset()
userInput.inputView = agePicker
userInput.becomeFirstResponder()
}
我要做的是实现两个 3D Touch 快速操作,一个称为Weight Search(运行代码func weightSearch),另一个称为Age Search(运行代码func ageSearch)。这是我到目前为止所做的:
- 在
Info.plist文件中,我创建了一个UIApplicationShortcutItems数组,其中包含两个Items字典类型,以及它们各自的UIApplicationShortcutItemTitle和UIApplicationShortcutItemType. 在我的
AppDelegate.swift文件中,我添加了初步的快速操作代码:func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) { //3D touch features }
我现在的问题是我不确定要为我的AppDelegate.swift文件编写什么代码。我看过的所有教程和该站点上的所有类似问题都涉及ViewController使用快速操作调用不同的函数,而不是在同一个 `ViewController. 先感谢您。