NSButton in NSTableCellView: How to find desired objectValue?

三世轮回 提交于 2019-12-05 15:22:08

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];
}

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.

I found an additional answer: The Answer above seems to assume you're using bindings on your table view. Since I'm kind of a noob I found a way to get the button inside the table view cell.

- (IBAction)getCellButton:(id)sender {
     int row = [xmlTable rowForView:sender];
}

This way when you click on the button inside the row, you don't have to have the row selected. It will return the int value of the row to match up with a datasource in an array without bindings.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!