如何获得经过编辑的NSOutlineView文本字段单元格的“项目”或行索引?

时间:2019-01-24 06:53:47

标签: swift macos nstableview nsoutlineview

我将NSOutlineView与文本字段/文本字段单元格结合使用,如下图所示:

hierarchically correct main element

enter image description here

已发送动作函数的代码:

@IBAction func handleTextFieldDidEndEditing(_ sender: Any) {
    print("LeftNavBarOutlineView selectedRow: \(self.selectedRow)")
    print("LeftNavBarOutlineView editedRow: \(self.editedRow)")
    print("LeftNavBarOutlineView selectedRowIndexes.count: \(self.selectedRowIndexes.count)")

    let taskName = (sender as! NSTextField).stringValue
    print("LeftNavBarOutlineView " + taskName)
}

打印结果:

LeftNavBarOutlineView selectedRow: -1
LeftNavBarOutlineView editedRow: -1
LeftNavBarOutlineView selectedRowIndexes.count: 0
LeftNavBarOutlineView

问题:

“发送者” 对象是一个NSTextField实例。我需要检索我的func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any函数返回的“项目”

我要么需要直接获取“ item”,要么需要获得行索引(可以从地图词典中检索“ item”)

由于“发送者”是一个NSTextField,我如何找出刚刚被编辑的行(或“项目”)是什么?

谢谢!

1 个答案:

答案 0 :(得分:2)

使用row(for view获取行,使用item(atRow获取项目

<script>

$(document).on("click","#user",function(){
    load_data();
});

  function load_data()
  {
    $.ajax({
      url:"fetch.php",
      method:"POST",
      success:function(data)
      {
        $('#user_data').html(data);
      }
    });
  }  

<script>

<script type='text/javascript'> function addFields() { var number = document.getElementById("member").value; var container = document.getElementById("container"); var optionsSelect = [ { id: 1, title: 'Option 1' }, { id: 2, title: 'Option 2' }, { id: 3, title: 'Option 3' } ]; while (container.hasChildNodes()) { container.removeChild(container.lastChild); } for (i = 0; i < number; i++) { var select = document.createElement('select'); for (var j = 0; j < optionsSelect.length; j++) { var options = document.createElement("option"); options.value = optionsSelect[j].id; options.text = optionsSelect[j].title; select.appendChild(options); } container.appendChild(select); container.appendChild(document.createTextNode(" -> Description " + (i + 1) + " ")); var input = document.createElement("input"); input.type = "text"; container.appendChild(input); container.appendChild(document.createElement("br")); } } </script> @IBAction func handleTextFieldDidEndEditing(_ sender: NSTextField) { let row = outlineView.row(for: sender) let item = outlineView.item(atRow: row) 实例