objective-c - 在 NSTableView 中禁用滚动

标签 objective-c macos scroll nstableview nsscrollview

是否有一种简单的方法来禁用 NSTableView 的滚动。

似乎没有任何属性 [myTableView enclosingScrollView][[myTableView enclosingScrollView] contentView] 禁用它。

最佳答案

这对我有用:子类 NSScrollView,通过以下方式设置和覆盖:

- (id)initWithFrame:(NSRect)frameRect; // in case you generate the scroll view manually
- (void)awakeFromNib; // in case you generate the scroll view via IB
- (void)hideScrollers; // programmatically hide the scrollers, so it works all the time
- (void)scrollWheel:(NSEvent *)theEvent; // disable scrolling

@interface MyScrollView : NSScrollView
@end

#import "MyScrollView.h"

@implementation MyScrollView

- (id)initWithFrame:(NSRect)frameRect
{
    self = [super initWithFrame:frameRect];
    if (self) {
        [self hideScrollers];
    }

    return self;
}

- (void)awakeFromNib
{
    [self hideScrollers];
}

- (void)hideScrollers
{
    // Hide the scrollers. You may want to do this if you're syncing the scrolling
    // this NSScrollView with another one.
    [self setHasHorizontalScroller:NO];
    [self setHasVerticalScroller:NO];
}

- (void)scrollWheel:(NSEvent *)theEvent
{
    // Do nothing: disable scrolling altogether
}

@end

希望对您有所帮助。

关于objective-c - 在 NSTableView 中禁用滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12626288/

相关文章:

iphone - ARC 释放子类 NSObject,但不释放自定义 NSObject

node.js - 如何在 Windows 上的 Node.js 中获取文件的大小写精确路径?

jquery - Firefox 中的 javaScript 错误 - 无法使用事件类更新菜单项

android - 如何在android中的集中布局内制作textview选框

objective-c - -copy 什么时候返回可变对象?

iphone - 配置收到推送通知时播放的声音

oracle - cx oracle 导入错误

java - 带有 Java 7 的 Mac OSX 上的透明 JFrame/JWindow

html - 带有滚动动画的 3 部分分割网站

ios - 用户界面 TextView /NSAttributedString : iOS Bug?