如何以编程方式添加可滚动NSTableView [英] How to add a scrollable NSTableView programmatically

查看:103
本文介绍了如何以编程方式添加可滚动NSTableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图添加一个tableview代码中的视图,而不是使用Interface Builder,不幸的是它导致一些问题=(

I'm trying to add a tableview to a view in code instead of using Interface Builder and unfortunately it's causing some problems =(

这里是一个例子,

NSScrollView *scrollView = [[NSScrollView alloc] initWithFrame:someRect];
NSTableView *tableView = [[NSTableView alloc] initWithFrame: scrollView.bounds];
resultsTableView.dataSource = self;

resultsScrollView.documentView = tableView;

[someView addSubview: scrollView];

所以基本上我只是把tableView放在scrollView做),然后添加后者作为someView的子视图,结果是一个tableView出现 - 但没有数据显示在tableView。调试显示,dataSource被要求在tableView中有多少行,但是方法:

So basically I'm just putting the tableView inside the scrollView (because that's what IB is doing) and then adding the latter as a subview of the someView. The result is that a tableView appears - but the no data is shown within the tableView. Debugging shows that the dataSource is being asked for how many rows are in the tableView but the method:

tableView:objectValueForTableColumn:row:

永远不会被调用。我怀疑这是因为我的创建tableView的方式。

is never being called. I suspect that this is because of my way of creating the tableView.

我试过google但没有运气和macdevcenter上的表视图编程指南有用的。

I've tried google but no luck and the "Introduction to Table Views Programming Guide" on macdevcenter wasn't helpful either. What am I missing?

提前感谢...

推荐答案


结果是显示一个tableView - 但是没有数据显示在tableView中。调试显示,正在询问dataSource在tableView中有多少行,但方法如下:

The result is that a tableView appears - but the no data is shown within the tableView. Debugging shows that the dataSource is being asked for how many rows are in the tableView but the method:

tableView:objectValueForTableColumn:row:

从未被呼叫。

它不要求您为任何列的对象值,因为它没有任何列。创建一些 NSTableColumn 实例和将它们添加到表视图

It's not asking you for the object values for any columns because it doesn't have any columns. Create some NSTableColumn instances and add them to the table view.

这篇关于如何以编程方式添加可滚动NSTableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆