代码之家  ›  专栏  ›  技术社区  ›  Andy

动态隐藏可安装视图中的列

  •  2
  • Andy  · 技术社区  · 16 年前

    我希望根据将要显示的数据动态隐藏/显示“可安装”视图中的某些列-基本上,如果列为空,我希望隐藏该列。我目前正在用一个控制器类作为表的委托来填充表。

    有什么想法吗?我看到可以在接口生成器中设置隐藏的列,但是似乎没有合适的时间来检查这些列是否为空,因为在填充表中的所有数据之前/之后似乎没有调用的方法。

    8 回复  |  直到 6 年前
        1
  •  0
  •   Mecki    16 年前

        2
  •  11
  •   Cameron Hotchkies    12 年前

    setHidden: selector

    NSInteger colIdx;
    NSTableColumn* col;
    
    colIdx = [myTable columnWithIdentifier:@"columnIdent"];
    col = [myTable.tableColumns objectAtIndex:colIdx];
    [col setHidden:YES];
    
        3
  •  3
  •   amrox    16 年前

    NSTableColumn *aColumn = [[NSTableColumn alloc] initWithIdentifier:attr];
    [aColumn setWidth:DEFAULTCOLWIDTH];
    [aColumn setMinWidth:MINCOLWIDTH];
    [[aColumn headerCell] setStringValue:columnLabel];
    
    [aColumn bind:@"value"
         toObject:arrayController 
      withKeyPath:keyPath 
      options:nil];             
    
    [tableView addTableColumn:aColumn];
    [aColumn release];
    

        4
  •  1
  •   Matthew Schinckel    16 年前

        5
  •  1
  •   Daniel    9 年前

    tableView.tableColumnWithIdentifier("Status")?.bind("hidden", toObject: NSUserDefaults.standardUserDefaults(), withKeyPath: "TableColumnStatus", options: nil)
    

    [[self.tableView tableColumnWithIdentifier:@"Status"] bind:@"hidden" toObject:[NSUserDefaults standardUserDefaults] withKeyPath:@"TableColumnStatus" options:nil];
    
        6
  •  0
  •   wompf    16 年前

        7
  •  0
  •   Andy    16 年前

        8
  •  0
  •   Lookaji    6 年前

    isHidden hideColumnsFlag

    class ViewController: NSViewController {
    
         // define the boolean binding variable to hide the columns and use its name as keypath
         @objc dynamic var hideColumnsFlag = true
    
         // Referring the column(s)
         // Method 1: creating IBOutlet(s) for the column(s): just ctrl-drag each column here to add it
         @IBOutlet weak var hideableTableColumn: NSTableColumn!
         // add as many column outlets as you need...
    
         // or, if you prefer working with columns' string keypaths
         // Method 2: use just the table view IBOutlet and its column identifiers (you **must** anyway set the latter identifiers manually via IB for each column)
         @IBOutlet weak var theTableView: NSTableView! // this line could be actually removed if using the first method on this example, but in a real case, you will probably need it anyway.
    
         // MARK: View Controller Lifecycle
    
         override func viewDidLoad() {
             super.viewDidLoad()
    
             // Method 1
             // referring the columns by using the outlets as such:
             hideableTableColumn.bind(.hidden, to: self, withKeyPath: "hideColumnsFlag", options: nil)
             // repeat for each column outlet.
    
             // Method 2
             // or if you need/prefer to use the column identifiers strings then:
             // theTableView.tableColumn(withIdentifier: .init("columnName"))?.bind(.hidden, to: self, withKeyPath: "hideColumnsFlag", options: nil)
             // repeat for each column identifier you have set.
    
             // obviously use just one method by commenting/uncommenting one or the other.
         }
    
         // MARK: Actions
    
         // this is the checkBox action method, just toggling the boolean variable bound to the columns in the viewDidLoad method.
         @IBAction func hideColumnsCheckboxAction(_ sender: NSButton) {
             hideColumnsFlag = sender.state == .on
         }
    }
    

    Hidden Enabled Editable