NSButton在NSTableCellView:如何找到所需的objectValue? [英] NSButton in NSTableCellView: How to find desired objectValue?

查看:535
本文介绍了NSButton在NSTableCellView:如何找到所需的objectValue?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于视图的NSTableView通过绑定填充。我的文本字段imageViews绑定到NSTableCellView的objectValue的属性。

I have a view-based NSTableView that is populated through bindings. My textFields & imageViews are bound to the NSTableCellView's objectValue's properties.

如果我想在NSTableCellView中有一个编辑/信息按钮:

If I want to have an edit/info button in my NSTableCellView:


  1. 谁应该是按钮操作的目标?

  1. Who should be the target of the button's action?

目标如何获取与按钮所在单元格相关联的objectValue ?

How would the target get the objectValue that is associated with the cell that the button is in?

我最终希望根据objectValue显示一个popover / sheet。

I'd ultimately like to show a popover/sheet based on the objectValue.

推荐答案

您的控制器类可以是目标。要获取对象值:

Your controller class can be the target. To get the object value:

- (IBAction)showPopover:(id)sender {
    NSButton *button = (NSButton *)sender;
    id representedObject = [(NSTableCellView *)[button superview] objectValue];
}

或者使用 NSTableCellView ,使单元格查看按钮操作的目标,并调用 [self objectValue] 获取对象。

Or, use a subclass of NSTableCellView, make the cell view the target of the button's action, and call [self objectValue] to get the object.

这篇关于NSButton在NSTableCellView:如何找到所需的objectValue?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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