数据源和 NSTableView
我知道表源需要一个数据源来保存表视图将显示的数据。 假设我要让我的 AppController 成为我的表视图的数据源,并且我在界面生成器中进行连接。我的问题是,因为我的实际数据将存储在一个数组中,我们称之为 myArray,当我在代码中设置数据源时,我应该这样做吗?
[tableView setDataSource:myArray]; or this [tableView setDataSource:self];
我对此感到困惑。如果我没有记错的话,使用关键字“self”设置数据源会将其设置为AppController。
I know that table sources need a data source to hold the data that the tableview will display.
Lets' say that I'm going to make my AppController be the data source of my tableview and that I make the connection in interface builder. My question is since my actual data is going to be stored in an array,let's call it myArray, when I set the data source in code should I do this
[tableView setDataSource:myArray]; or this [tableView setDataSource:self];
I'm confused about this. setting the data source with the keyword "self" would set it to the AppController if I'm not mistaken.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
表视图数据源必须符合
NSTableViewDataSource
协议(在 10.6 之前称为NSTableDataSource
)。NSArray
不符合此协议,因此不能将其用作数据源。您需要在
AppController
对象中实现所需的协议方法,并将AppController
对象指定为表的数据源。A table view data source must conform to the
NSTableViewDataSource
protocol (calledNSTableDataSource
prior to 10.6).NSArray
does not conform to this protocol, so you can't use it as a data source.You need to implement the required protocol methods in your
AppController
object and assign yourAppController
object as the table's data source.