1
votes

i try to get my head around view-based NSTableViews on OS X.

My Problem is that in the loaded view cell (NSView subclass) the subviews are not initialized when i try to assign the values in my delegate.

At the moment the correct count and the correct view is displayed, but i cannot access the subviews to assign the proper values.

What i have done so far:

  • Created the xib with the custom view cell in Interface Builder.
  • Created the custom class for the cell and assigned it in IB.

This work fine and i can see the properties in the Debugger. Correct class and the properties are IBOulets that are wired to the correct fields.

I can see the call to:

- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row

In my NSViewController:awakeFromNib i do:

// Make my view controller the delegate
_applicationTableView.delegate = self;
// set the correct datasource
_applicationTableView.dataSource = [NWDataHolder sharedInstance];
// register the nib with the custom cell
[_applicationTableView registerNib:cellNib forIdentifier:@"ApplicationListViewCell"];

In my - (NSView *)tableView:viewForTableColumn:row: i do:

NWApplicationListViewCell *cell = [_applicationTableView makeViewWithIdentifier:@"ApplicationListViewCell" owner:self];

The correct class and cell is returned and i have access to the properties. The problem is, that subview is not initialized, the property is nil and the new value could not be set:

Log(@"Application Name Label %@", cell.applicationNameLabel); => nil

I`ve seen some hints that the subviews are initialized lazyly, but i cannot find a way to make the eager initialize.

Any suggestions what i'm doing wrong ?

Thanks, Oliver

1
Your cell subclass has an outlet called applicationNameLabel, and you connected that up to the label in the xib file?rdelmar
Correct. I wired the subviews, mostly labels to display the informations, via IB to Outlets. THe only thing that i stumbled upon is that when i access these Outlets they are not initialized when i create the view via NWApplicationListViewCell *cell = [_applicationTableView makeViewWithIdentifier:@"ApplicationListViewCell" owner:self];. After this the subviews are still nil.Odo

1 Answers

1
votes

Fixed the problem. But i do not understand why this really happens.

I wired the fields in IB to the File Owner, but not to my ApplicationViewCell. After wiring the property to both everything works fine.