cocoa – 如何在NSTableCellView中单击NSTextView时在NSTableView中选择一行?

cocoa – 如何在NSTableCellView中单击NSTextView时在NSTableView中选择一行?,第1张

概述我有一个基于视图的单列NSTableView.在我的NSTableCellView子类中,我有一个可选的NSTextView,但不可编辑. 当用户直接单击NSTableCellView时,该行会正确突出显示.但是当用户单击NSTableCellView内的NSTextView时,该行不会突出显示. 如何将NSTextView上的单击传递给NSTableCellView以使该行突出显示? 类层次结构 我有一个基于视图的单列NStableVIEw.在我的NStableCellVIEw子类中,我有一个可选的NSTextVIEw,但不可编辑.

当用户直接单击NStableCellVIEw时,该行会正确突出显示.但是当用户单击NStableCellVIEw内的NSTextVIEw时,该行不会突出显示.

如何将NSTextVIEw上的单击传递给NStableCellVIEw以使该行突出显示?

类层次结构如下所示:
NSScrollVIEw> NStableVIEw> NStableColumn> NStableCellVIEw> NSTextVIEw

解决方法 这就是我最终做的事情.我创建了NSTextVIEw的子类并覆盖了mouseDown:如下所示……

- (voID)mouseDown:(NSEvent *)theEvent{    // Notify delegate that this text vIEw was clicked and then    // handled the click natively as well.    [[self myTextVIEwDelegate] dIDClickMyTextVIEw:self];    [super mouseDown:theEvent];}

我正在重用NSTextVIEw的标准委托……

- (ID<MyTextVIEwDelegate>)myTextVIEwDelegate{    // See the following for info on formal protocols:    // stackoverflow.com/questions/4635845/how-to-add-a-method-to-an-existing-protocol-in-cocoa    if ([self.delegate conformstoprotocol:@protocol(MyTextVIEwDelegate)]) {        return (ID<MyTextVIEwDelegate>)self.delegate;    }    return nil;}

在标题中……

@protocol MyTextVIEwDelegate <NSTextVIEwDelegate>- (voID)dIDClickMyTextVIEw:(ID)sender;@end

在委托中,我实现了dIDClickMyTextVIEw:来选择行.

- (voID)dIDClickMyTextVIEw:(ID)sender{    // User clicked a text vIEw. Select its underlying row.    [self.tableVIEw selectRowIndexes:[NSIndexSet indexSetWithIndex:[self.tableVIEw rowForVIEw:sender]] byExtendingSelection:NO];}
总结

以上是内存溢出为你收集整理的cocoa – 如何在NSTableCellView中单击NSTextView时在NSTableView中选择一行?全部内容,希望文章能够帮你解决cocoa – 如何在NSTableCellView中单击NSTextView时在NSTableView中选择一行?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1005494.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存