jeudi 21 juin 2018

Swift Cocoa - Selected checkbox cell in NSTableview

I'm learning to create a simple program in Cocoa swift. What I'm trying to do here is to create a tableview with 2 columns. One for CheckBox and one for TextView.

Simple Cocoa app

But I cannot change the checkbox state when click on the checkbox. What I need is when I click a checkbox, it's select that row on the tableview. Are there any event for the checkbox so I can check it?

Here is my code

import Cocoa

let Mydirectory: [String] = ["John", "Davis", "Mark", "Sarah", "Kim", 
"Hanna"]

class ViewController: NSViewController, NSTableViewDataSource, 
NSTableViewDelegate {

override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.
}

override func awakeFromNib() {

}

@IBOutlet weak var table: NSTableView!

override var representedObject: Any? {
    didSet {
    // Update the view, if already loaded.
    }
}

func numberOfRows(in tableView: NSTableView) -> Int {
    return Mydirectory.count
}

func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {

    return Mydirectory[row]
}
}




Aucun commentaire:

Enregistrer un commentaire