NSOutlinview use the scrollRowToVisible method,cause the outlineView(_ outlineView: NSOutlineView, shouldSelectItem item: Any) -> Bool called
I developed a cocoa app. I used 'NSOutlineView' to show my data and in the 'outlineView(_ outlineView: NSOutlineView, shouldSelectItem item: Any) -> Bool' method, I insert a new row like this 'outlineView.insertItems(at: index, inParent: parent, withAnimation: [])'. In the 'outlineView(_ outlineView: NSOutlineView, didAdd rowView: NSTableRowView, forRow row: Int)', I use the ' outLineView.scrollRowToVisible(row + 1)' method for the last row showing, but the 'outlineView(_ outlineView: NSOutlineView, shouldSelectItem item: Any) -> Bool' method will call again. How can I prevent the 'outlineView(_ outlineView: NSOutlineView, shouldSelectItem item: Any) -> Bool' method to be called again?
func outlineView(_ outlineView: NSOutlineView, shouldSelectItem item: Any) -> Bool {
if let element : FUEElementModel = item as? FUEElementModel {
return false
}else if let element : FUEElementSubAddModel = item as? FUEElementSubAddModel {
// 首先结束nowShowRightAttributeVC的编辑
endAttributeVCEdit()
isAddItem = true
let parent : FUEElementModel = element.parent!
var subItem : FUEElementSubModel!
if parent.type == .ThreeD{
subItem = FUEElement3DDefaultNoScrollSubModel.init(title: "subItem\(document.subItemIndex)")
}else{
subItem = FUEElementSubModel.init(title: "subItem\(document.subItemIndex)")
}
document.subItemIndex += 1
let index = parent.insertChildAtLast(newElement :subItem)
outlineView.insertItems(at: index, inParent: parent, withAnimation: [])
return false
}else if let element : FUEElementSubModel = item as? FUEElementSubModel {
// 首先结束nowShowRightAttributeVC的编辑
endAttributeVCEdit()
let parent : FUEElementModel = element.parent!
if parent.type! == .ThreeD{
if element.type == .ThreeDGlobalAttribute{
rightThreeDAttributeVC.threeDViewType = .Global
rightThreeDAnimationVC.threeDViewType = .Global
}else if element.type == .ThreeDDefaultNoScrollAttribute{
rightThreeDAttributeVC.threeDViewType = .defaultNoScrollAttribute
rightThreeDAnimationVC.threeDViewType = .defaultNoScrollAttribute
}else if type(of: element) == FUEElement3DDefaultSubModel.self{
return false
}
}
operationType = .Select
// 临时补一下 防止崩溃
shoulSelectItem = element
parenElementType = parent.type!
shoulSelectItem = nil
// 根据是否可以删除,返回是否选中
} else if let element : FUEElement3DDefaultTLSubModel = item as? FUEElement3DDefaultTLSubModel {
seleted3DDefaultTLSubModel = element
rightThreeDAttributeVC.threeDViewType = .defaultAttribute
rightThreeDAnimationVC.threeDViewType = .defaultAttribute
operationType = .Select
parenElementType = .ThreeD
seleted3DDefaultTLSubModel = nil
}
return true
}
func outlineView(_ outlineView: NSOutlineView, didAdd rowView: NSTableRowView, forRow row: Int) {
if isAddItem{
operationType = .Add
outLineView.selectedRowIndexes.forEach{index in outLineView.deselectRow(index)
}
print("didAdd--------\(row)")
outlineView.selectRowIndexes(IndexSet(integer:row), byExtendingSelection: true)
let selectedItem = getSeletedItem()
let parent = selectedItem?.parent
if parent?.type == .ThreeD{
rightThreeDAttributeVC.threeDViewType = .defaultNoScrollAttribute
rightThreeDAnimationVC.threeDViewType = .defaultNoScrollAttribute
}
parenElementType = parent?.type
outLineView.scrollRowToVisible(row + 1)
// let position = outLineView.rect(ofRow: row)
// outLineView.scroll(position.origin)
}
isAddItem = false
}
Comments
Post a Comment