K...我是全新的(基本上是阅读 Apple 的开发人员文档)。(对不起,如果我重复发布,但我找不到答案)
我有一个带有 2 个 ViewControllers 的简单应用程序(由 FreeLancer 付费开发)。第一个有 2 个按钮,点击后会将您带到第二个 ViewController 中的特定文本框(用于输入)。
(经过一些研究)我能够添加 2 个静态 QuickAction。我希望光标/焦点根据所选的 QuickAction 转到相应的文本框。采取快速操作后,我可以打开一个对话框,但就是这样。
例如:3d Touch 并点击“Go to Name”快速操作,将带我到第二个 ViewController 中的 txtFirstName。
ViewController2nd 中的代码(点击 1stViewController 中的相应按钮后):
class ViewController2nd: UIViewController, UITextFieldDelegate,
CLLocationManagerDelegate {
@IBOutlet weak var txtFirstName: UITextField!
@IBOutlet weak var txtSecondName: UITextField!
var nTouched : Int = 0
override func viewDidLoad()
{
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
txtFirstName.delegate = self
txtSecondName.delegate = self
if(nTouched == 1)
{
txtFirstName.becomeFirstResponder()
}
else if(nTouched == 2)
{
txtSecondName.becomeFirstResponder()
}
AppDelegate 中用于 QuickAction 的代码(有效):
QuickActions UIApplicationShortcutItemType 是“AddFirst”和“AddSecond”。
//called when QA tapped
func notifyUser(message: String) {
let alertController = UIAlertController(title: "Quick Action
Triggered",
message: message,
preferredStyle: .Alert)
let okAction = UIAlertAction(title: "OK",
style: .Default,
handler: nil)
alertController.addAction(okAction)
window!.rootViewController?.presentViewController(alertController,
animated: true, completion: nil)
}
//end
func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
switch (shortcutItem.type) {
case “AddFirst” :
//will comment out after it's working
notifyUser(shortcutItem.localizedTitle)
case “AddSecond“ :
//will comment out after it's working
notifyUser(shortcutItem.localizedTitle)
default:
break
}
completionHandler(true)
}
所以我想问题是我需要在 Case 语句中放入什么代码才能将我带到 2ndviewcontroller 中的正确文本框?
谢谢大家!