NSTableView:只有numberOfRowsInTableView:datasource被调用 [英] NSTableView: only numberOfRowsInTableView: datasource is called
问题描述
我遇到了一个关于 NSTableView
的问题,它就像:
tableview的一个数据源被调用:
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];
}
但是这个不会被调用:
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
{
// the code
}
我已经检查数组真的有数据,
[NSTableView reloadData]
在主线程中调用。
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!
推荐答案
我从 awakeFromNib
到 init
,它被正确调用。但我还是不知道真正的原因。我想这与视图的生命周期有关,因为有tableview的类是 NSObject
的子类,而不是 NSViewController
。
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
.
这篇关于NSTableView:只有numberOfRowsInTableView:datasource被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!