objective-c – 如何确定用户是否已滚动到NSTableView的末尾

我有一个NSTableView,我想知道用户何时滚动到底部,所以我可以执行一个动作.不太清楚如何去做?

更新:
以下是我计算表格底部方法

-(void)tableViewDidScroll:(CPNotification) notification
{
    var scrollView = [notification object];
    var currentPosition = CGRectGetMaxY([scrollView visibleRect]);
    var tableViewHeight = [messagesTableView bounds].size.height - 100;

    //console.log("TableView Height: " + tableViewHeight);
    //console.log("Current Position: " + currentPosition);

    if (currentPosition > tableViewHeight - 100)
    {
       console.log("we're at the bottom!");
    }
}

解决方法

您可以从表的-enclosingScrollView的-contentView中添加自己作为观察者(在NSNotificationCenter意义上,而不是KVO / Bindings意义上)NSViewBoundsDidChangeNotification,并根据可见矩形进行必要的反应.

更新

在某个地方做这个(也许是-awakeFromNib):

// Configure the scroll view to send frame change notifications
id clipView = [[tableView enclosingScrollView] contentView];
[[NSNotificationCenter defaultCenter] addobserver:self
                                         selector:@selector(myBoundsChangeNotificationHandler:)
                                             name:NSViewBoundsDidChangeNotification
                                           object:clipView];

把它放在有用的地方:

- (void)myBoundsChangeNotificationHandler:(NSNotification *)aNotification
{

if ([aNotification object] == [[tableView enclosingScrollView] contentView])
    [self doSomethingInterestingIfDocumentVisibleRectSatisfiesMe];

}

基本上你想要检查滚动视图的-documentVisibleRect,看看底部几个像素是否可见.请记住使用翻转坐标系统来考虑视图的可能性 – “翻转视图” – 在Views Programming Guide中介绍.

相关文章

我正在用TitaniumDeveloper编写一个应用程序,它允许我使用Ja...
我的问题是当我尝试从UIWebView中调用我的AngularJS应用程序...
我想获取在我的Mac上运行的所有前台应用程序的应用程序图标....
我是一名PHP开发人员,我使用MVC模式和面向对象的代码.我真的...
OSX中的SetTimer在Windows中是否有任何等效功能?我正在使用...
我不确定引擎盖下到底发生了什么,但这是我的设置,示例代码和...