Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS 13中的Uitassintitem如何与自定义inputView一起工作?_Ios_Swift_Ios13_Inputview - Fatal编程技术网

iOS 13中的Uitassintitem如何与自定义inputView一起工作?

iOS 13中的Uitassintitem如何与自定义inputView一起工作?,ios,swift,ios13,inputview,Ios,Swift,Ios13,Inputview,我有一个带有一个文本字段的视图控制器,我将文本字段用于键盘快捷键栏的每个组(前导和尾随)的按钮,简单如下: class MyViewController: UIViewController { @IBOutlet weak var textField: UITextField! override func viewDidLoad() { super.viewDidLoad() setupKeypad() } private

我有一个带有一个文本字段的视图控制器,我将文本字段用于键盘快捷键栏的每个组(前导和尾随)的按钮,简单如下:

class MyViewController: UIViewController {

    @IBOutlet weak var textField: UITextField!

    override func viewDidLoad() {
        super.viewDidLoad()

        setupKeypad()
    }

    private func setupKeypad() {
        let item: UITextInputAssistantItem = textField.inputAssistantItem
        let doneButton = UIButton()
        doneButton.setTitle("done", for: .normal)
        doneButton.addTarget(self, action: #selector(donePressed), for: .touchUpInside)

        let cancelButton = UIButton()
        cancelButton.setTitle("cancel", for: .normal)
        cancelButton.addTarget(self, action: #selector(cancelPressed), for: .touchUpInside)

        let rightBarButtonItem = UIBarButtonItem(customView: doneButton)
        let leftBarButtonItem = UIBarButtonItem(customView: cancelButton)

        let leftGroup = UIBarButtonItemGroup(barButtonItems: [leftBarButtonItem], representativeItem: nil)
        let rightGroup = UIBarButtonItemGroup(barButtonItems: [rightBarButtonItem], representativeItem: nil)

        item.leadingBarButtonGroups = [leftGroup]
        item.trailingBarButtonGroups = [rightGroup]
    }

    @objc func donePressed() {
        print(#function)
    }

    @objc func cancelPressed() {
        print(#function)
    }
}
没有什么特别的,只需在
viewDidLoad()
方法中调用
setupKeypad()
即可添加这两个按钮。它工作正常:

但是,当尝试为文本字段添加自定义
inputView
时,快捷键栏不再显示:

override func viewDidLoad() {
    super.viewDidLoad()

    // adding dummy custom view as inputView for the textField
    let customView = UIView(frame: CGRect(x: 0, y: 0, width: 300.0, height: 300.0))
    customView.backgroundColor = .orange
    textField.inputView = customView

    setupKeypad()
}
结果是:

我在以前的iOS版本(12.4-)上仔细检查了它,它在自定义
inputview
中运行良好。例如,iOS 12.2的结果是:

如何解决这个问题