问题描述
我在10.8上运行基于视图的NSTableView时遇到了问题(目标是10.7,但我认为这不相关)。
I'm facing a problem with a view-based NSTableView running on 10.8 (target is 10.7, but I think this is not relevant).
我使用NSTableView,然后通过绑定获取自定义NSTableCellView的内容值。我使用NSTableCellView的obejctValue来获取数据。
I'm using an NSTableView, and I get content values for my custom NSTableCellView through bindings. I use the obejctValue of the NSTableCellView to get my data.
我在单元格中添加了一个按钮,我希望它在单击时触发一些操作。到目前为止,我只能在自定义NSTableCellView的子类中触发操作。
I added a button to my cell, and I'd like it to trigger some action when clicked. So far I have only been able to trigger an action within the custom NSTableCellView's subclass.
我可以使用链来获得被单击的行:
I can get the row that was clicked like this, using the chain:
NSButton *myButton = (NSButton*)sender;
NSTableView *myView = (NSTableView*)myButton.superview.superview.superview;
NSInteger rowClicked = [myView rowForView:myButton.superview];
从那里我不知道如何到达定义了操作的App Delegate或控制器。
From there I don't know how to reach my App Delegate or controller where the action is defined.
当我使用可可粉绑定时,我在NSTableView上没有可用来触发动作的委托。
As I am using cocoa bindings, I do not have a delegate on the NSTableView that I could use to trigger my action.
您是否知道如何与控制器对话?
Do you have any idea how I could talked back to controller ?
非常感谢!
推荐答案
尽管您正在使用绑定,但仍可以在界面构建器中将控制器设置为表视图的委托。
Although you are using bindings you can still set your controller as the delegate for your tableview in the interface builder.
我看到您已经能够从单元内部访问表视图。下一个任务必须很简单,只需将表格视图委托设置为按钮操作的目标即可。
I see that you already are able to access the table view from inside your cell. The next task must be simple, just set the table view delegate as the target for your button's action.
这篇关于使用绑定时如何在基于视图的NSTableView中从NSTableCellView触发操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!