重做不能迅速在UndoManager中工作

问题描述 投票:1回答:1

我正在代码中实现撤消/重做功能,但由于某种原因,我的重做功能无法正常工作,这是我的文本视图代码:

  func textViewDidBeginEditing(_ textView: UITextView) {
    if descBox.textColor == .lightGray {
        DescriptionCell.descPlaceholder = descBox.text
            let descText = descBox.text
            undoManager?.registerUndo(withTarget: self, handler: {
            (targetSelf) in
            targetSelf.descBox.text = descText
            targetSelf.descBox.textColor = .lightGray
        })
        descBox.text = nil
        descBox.textColor = .black
    }
}

func textViewDidEndEditing(_ textView: UITextView) {
    if descBox.text.isEmpty {
        descBox.text = DescriptionCell.descPlaceholder
        descBox.textColor = .lightGray
    }
        let descText = descBox.text
        undoManager?.registerUndo(withTarget: self, handler: {
            (targetSelf) in
            targetSelf.descBox.text = descText
        })
        }

然后我将其用于ViewController工具栏:

@objc func Undo() {
 undoManager?.undo()
}

@objc func Redo() {
 undoManager?.redo()
}

然后在viewDidLoad中:

let undoKeyboard = UIBarButtonItem(image: UIImage(named: "Image-2"), style: .plain, target: self, action: #selector(Undo))
    undoKeyboard.tintColor = .lightGray
let redoKeyboard = UIBarButtonItem(image: UIImage(named: "Image-1"), style: .plain, target: self, action: #selector(Redo))
    redoKeyboard.tintColor = .green
ios swift xcode undo-redo nsundomanager
1个回答
0
投票
问题在这里:
© www.soinside.com 2019 - 2024. All rights reserved.