问题描述
我有一个可滚动的 NSTextView
,其中包含链接到 NSTableView
单元格的唯一文本。当我选择不同的 NSTableView
单元格并更新 NSTextView
以保持其新的 NSAttributedString
值时,撤消和重做功能变得混乱,所以我想我会尝试删除滚动视图并重新每次我想更新它时都添加它以希望重置撤消/重做链。
这是我目前的代码:
var scrollView: NSScrollView = {
let scroll = NSTextView.scrollableTextView()
scroll.translatesAutoresizingMaskIntoConstraints = false
return scroll
}()
var textView: NSTextView = {
let view = NSTextView()
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
func updateView() { // my function to call when a new tableview cell is selected
self.scrollView.removeFromSuperview()
textView = scrollView.documentView as! NSTextView
self.addSubView(scrollView)
self.setUpConstraints() // my function containing layout constraints
}
但只有空格。这是我的 setUpConstraints()
函数:
func setUpConstraints() { // I have other constraints in my program which relate to each other. All working.
let scrollViewConstraints = [
scrollView.topAnchor.constraint(equalTo: self.topAnchor,constant: 10),scrollView.leftAnchor.constraint(equalTo: self.leftAnchor,constant: 15),scrollView.rightAnchor.constraint(equalTo: self.rightAnchor,constant: -14),scrollView.bottomAnchor.constraint(lessthanorEqualTo: self.bottomAnchor,constant: -20)
]
let allConstraints = [
scrollViewConstraints
]
for constraints in allConstraints {
NSLayoutConstraint.activate(constraints)
}
}
我还有其他视图,例如 NSTextField
,我正在以完全相同的方式处理它们,它们都可以正常工作。问题是我可以把 self.addSubView(scrollView)
放在 viewDidMovetoSuperview
中就好了,但是当我把它放在我的 updateView
函数中时,它不起作用。 (仅供参考:updateView 是我的表视图的委托函数)
我也对我的撤消/重做问题的其他解决方案持开放态度。
提前致谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)