1
votes

So I'm using NSArrayController with my NSTableView and I want to show custom row color even NSArrayController doesn't have any objects.

Normally without Cocoa bindings I can just "cheat" my numberOfRows like this:

var dataStore = [Person]()

func numberOfRowsInTableView(tableView: NSTableView) -> Int {
    if dataStore.count < 20 {
        return 20
    } else {
        return dataStore.count
    }
}

And then getting custom row colors...

func tableView(tableView: NSTableView, didAddRowView rowView: NSTableRowView, forRow row: Int) {
    if row % 2 == 0 { rowView.backgroundColor = NSColor.blueColor() }
    else { rowView.backgroundColor = NSColor.reColor() }
}

How I can get same effect for empty table view with Cocoa bindings?

1
The latter method is a delegate method, and you can still use those regardless of bindings, which really replace the datasource methodsstevesliva
Yes I know, but I need to get that working even there isn't any data. And that didAddRowView only works after added some data.Prontto

1 Answers

2
votes

I don't know about code for mac app but in ios app, I can easily achieve your need with cellForRowAtIndexPath. Did you try it?