NSTableView: only numberOfRowsInTableView: datasou

2019-06-07 22:20发布

问题:

I met a problem about the NSTableView, and it is like: one datasource of tableview is called:

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
{
    return [self.dataArray count];
}

But this one is never called:

- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
    // the code 
}

I have checked the the array really had data, and also checked the [NSTableView reloadData] was called in the main thread.

SO I'm totally lost about this weird problem. Would any one give some tips? thanks!

回答1:

I moved the initial code from awakeFromNib to the init, and it called correctly. But I still don't know the real reason. I guess it matters with the life-cycle of the view because the class which has the tableview is a subclass of NSObject and not of NSViewController.