She*_*lam 6 macos cocoa objective-c nstableview nsscrollview
我有一个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!");
}
}
Run Code Online (Sandbox Code Playgroud)
Jos*_*zzi 16
您可以从表的-enclosingScrollView的-contentView中添加自己作为NSViewBoundsDidChangeNotification的观察者(在NSNotificationCenter意义上,而不是KVO/Bindings意义上),并根据可见矩形进行必要的反应.
更新
在某处做这件事(也许是-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];
Run Code Online (Sandbox Code Playgroud)
把它放在有用的地方:
- (void)myBoundsChangeNotificationHandler:(NSNotification *)aNotification
{
if ([aNotification object] == [[tableView enclosingScrollView] contentView])
[self doSomethingInterestingIfDocumentVisibleRectSatisfiesMe];
}
Run Code Online (Sandbox Code Playgroud)
基本上你想要检查滚动视图-documentVisibleRect,看看底部几个像素是否可见.请记住使用翻转坐标系统来考虑视图的可能性 - "翻转视图" - 在" 视图编程指南"中介绍.
| 归档时间: |
|
| 查看次数: |
3291 次 |
| 最近记录: |