I have an NSTableView where I'd like to be able to highlight 1 or more rows, and then hit the delete key to delete them, or hit +C to copy them to the pasteboard.

I've found a suggestion to subclass the NSTableView and then code up a method for

-(void)copy:(id)sender

The documentation says that subclassing the NSTableView is rarely necessary. Instead, use the dataSource or delegate, or subclass a subcomponent. The delegate and dataSource protocols don't handle menu commands or keyboard short cuts. If I try to subclass anyways, I run into a problem where the subclass needs to send a message to the delegate, but my custom methods aren't part of the protocol, so the compiler complains. Rather than fight the design pattern, I'd rather know what the "correct" approach to this problem is.

有帮助吗?

解决方案

I solved my problem by declaring the NSTableView's parent window's delegate as the NSTableView's controller (which is also its dataSource and delegate). Now it receives menu actions as part of the responder chain.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top