NSComboBox 数据源和 reloadData
我的应用程序中有一个 NSCombobox,并且为其设置了一个数据源。
IBOutlet NSComboBox *comboBox;
我还在程序中的某个时刻指定:
[comboBox reloadData];
我的想法是,在这次调用之后,只要我记得设置组合框的数据源(我做到了),我就应该调用这些方法:
- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)index
- (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox
但我不这样做。这不是组合框的工作原理吗?
I have an NSCombobox in my app and I have a datasource set up for it.
IBOutlet NSComboBox *comboBox;
I also specify at some point in my program:
[comboBox reloadData];
My thought would be that after this call, I should get calls to these methods as long as I remembered to set the datasource of the combo box (which i did):
- (id)comboBox:(NSComboBox *)aComboBox objectValueForItemAtIndex:(NSInteger)index
- (NSInteger)numberOfItemsInComboBox:(NSComboBox *)aComboBox
But I don't. Is this not how combo boxes work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用带有数据源的组合框,并且您可以在组合首次绘制之前设置数据源方法所需的任何结构,则只需在数据随后发生更改时调用
reloadData
。如果根本没有调用数据源方法(无论是在调用
reloadData
之前还是之后),请确保将组合框配置为使用数据源。在笔尖中的组合框下,选择使用数据源,或在代码中调用[comboBox setUsesDataSource:YES]
。If you're using a combo box with a data source, and provided you can set up whatever structures the data source methods require before the combo first draws, you only need to call
reloadData
if the data subsequently changes.If the data source methods aren't being called at all – either before or after a call to
reloadData
– make sure the combo box is configured to use a data source. In the nib, under Combo Box, select Uses Data Source, or call[comboBox setUsesDataSource:YES]
in code.