Table related table bindings in Swift

I am trying to set up a view based table in Swift using bindings. All examples I've seen use the datasource / delegate setting.

I have an array of Flag objects that has two properties - flagName: String and flagImage: NSImage. I have an NSArrayController managing this array.

If I set up a honeycomb based table and bind one column to the ordered Objects.flagImage and the other to the ordered Objects.flagName, I end up with a table displaying images and names and I can use an array controller to add and remove methods, so no problem with my datasource or array controller.

I followed the instructions in the Apple TableView Programming Guide to bind my view-based table to my array controller:

  • tableView Content binding: FlagController.arrangedObjects
  • textField Value Binding: TableCellView.objectValue.flagName
  • imageView Value Binding: TableCellView.objectValue.flagImage

(IBs autocomplete is unhappy with the paths for objectValue.flagName, respectively flagImage, it doesn't feel like there should be any completion at all and says it can't resolve the path, so it looks like the problem is with the contents of the tableView.)

If I do this, my table has multiple rows that correspond to the number of elements that my array controller controls (I have two simple settings, one object versus 50 objects, so it clears something related). What I don't get is the display; and selecting a table row doesn't seem to send a message to my flagController.

What am I missing? Anyone could make this work? So far, I haven't had any problems with other connections in Swift, but I'm starting to think that the sudden appearance of data source examples has nothing to do with this.

+3


source to share


1 answer


It looks like you failed to implement the delegate method -tableView:viewForTableColumn:row:

. This is a common reason for empty tables.

You don't actually need to implement this as long as you make sure the table column ID and table cell view ID are the same in IB.

Otherwise, the method can simply do this:



- (NSView*) tableView:(NSTableView*)tableView viewForTableColumn:(NSTableColumn*)tableColumn row:(NSInteger)row
{
    return [tableView makeViewWithIdentifier:@"TheIdentifierOfYourTableCellView" owner:self];
}

      

(You can also do more if you want.)

+2


source







All Articles