最好的方法来处理多个NSTableView [英] Best way to handle multiple NSTableView(s)

查看:145
本文介绍了最好的方法来处理多个NSTableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在不使用Cocoa Bindings的情况下,处理多个NSTableView的最佳方式是什么?

What is considered the best way of handling multiple NSTableViews without using Cocoa Bindings?

在我的应用程序中,我有两个NSTableView,使用与两者的delegate和dataSource相同的对象。问题是两个tableViews调用相同的方法。我目前在NSControl -tag的基础上区分两个tableViews。

In my app, I have two NSTableViews that are sufficiently closely related that I'm using the same object as the delegate and dataSource for both. The problem is both tableViews invoke the same methods. I currently discriminate between the two tableViews on the basis of NSControl -tag.

我越深入这个代码,uglier使用-tag看起来。我最终创建主要是重复的代码,以区分每个委托/ dataSource方法中的tableViews。

The deeper I get into this code, the uglier the use of -tag looks. I end up creating largely duplicate code to distinguish between the tableViews in each delegate/dataSource method. The code ends up being distinctly non-object oriented.

我可以创建一个单独的对象来处理一个或另一个tableView,但是所述对象的创建将是一个很大程度上人工构造只是提供一个不同的委托/ dataSource。

I could create a separate object to handle one or the other tableView, but the creation of said object would be a largely artificial construct just to provide a distinct delegate/dataSource.

现在每个人都只使用Cocoa Bindings吗?我避免绑定,因为我想磨练我的Cocoa技能,可以在Mac OS和iPhone之间传输的技术。

Is everyone just using Cocoa Bindings now? I'm avoiding Bindings as I would like to hone my Cocoa skills on techniques that are transferrable between Mac OS and iPhone.

推荐答案

NSTableView的每个委托/ dataSource方法都传递NSTableView的实例,该实例调用它作为第一个参数(除了传递NSNotification对象的实例,在这种情况下NSNotification的 object 表视图实例)。一些示例包括:

Every delegate/dataSource method for NSTableView passes the instance of NSTableView that's calling it as the first parameter (except for the ones that pass NSNotification objects, in which case the NSNotification's object is the table view instance). Some examples include:

- (int)numberOfRowsForTableView :( NSTableView *)aTableView;

- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex

- (void)tableViewSelectionDidChange:(NSNotification *)aNotification

如果您使用一个控制器对象作为多个表的委托/数据源,您只需使用该参数来区分它们。

If you're using one controller object as a delegate/data source for multiple tables, you can just use that parameter to differentiate between them.

这篇关于最好的方法来处理多个NSTableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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