我是IOS的新手并且很快。有谁知道如何为boolean appdelegate方法赋值?我想在 viewcontroller 中设置shouldAllowExtensionPointIdentifier,但我找不到任何解决方案。谢谢
//
// AppDelegate.swift
// TestKeyboard
//
// Created by Mol Monyneath on 11/1/17.
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
public var Alow : Bool?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch
return true
}
func application(_ application: UIApplication, shouldAllowExtensionPointIdentifier extensionPointIdentifier: UIApplicationExtensionPointIdentifier) -> Bool {
print("\(extensionPointIdentifier.rawValue) allow = \(Alow)")
return Alow!
}
}
这是主视图控制器: 我无法阻止该应用。请帮忙
import UIKit
class ViewController: UIViewController,UITextFieldDelegate {
@IBOutlet weak var normaltextView: UITextField!
@IBOutlet weak var txtView: UITextField!
var appDelegate = UIApplication.shared.delegate as! AppDelegate
override func viewDidLoad() {
super.viewDidLoad()
normaltextView.delegate = self
txtView.delegate = self
}
func textFieldShouldBeginEditing(_ textField: UITextField) -> Bool {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
if textField.keyboardType == UIKeyboardType.numberPad{
// textField.inputView = nil
txtView.inputView = nil
appDelegate.Alow = false
txtView.reloadInputViews()
print("false")
}else{
print("should Press")
print("True")
// textField.inputView = nil
appDelegate.Alow = true
txtView.reloadInputViews()
normaltextView.reloadInputViews()
}
return true
}
}
感谢