将NSTableView滚动到endOfDocument而不是最后一行

问题描述 投票:0回答:1

我有NSTableView动态排高度。我需要滚动到最后。我尝试了scrollToEndOfDocument:,但它给出的结果与scrollRowToVisible:相同,后者是最后一行的开头

- (void)viewDidLoad {
    [super viewDidLoad];
    //[[self tableView] scrollRowToVisible:[[self tableView] numberOfRows] - 1];
    [[self tableView] scrollToEndOfDocument:self];
}

Example

macos cocoa nstableview nsscrollview
1个回答
1
投票

你的scrollRowToVisible方法应该有效。这是一个快速的sample project,它使用一个滚动到最后一行的按钮来实现可变高度。滚动后,最后一行完全可见。

TableScroll image

更新:对于大于周围NSClipView的表格单元格,上述技术将仅滚动到单元格的顶部。要滚动到最后一个单元格的底部,您可以使用:

let point = NSPoint(x: 0, y: tableView.frame.height)
tableView.scroll(point)

或者因为OP在ObjC:

[[self tableView] scrollPoint: NSMakePoint(0, [self tableView].frame.size.height)]
© www.soinside.com 2019 - 2024. All rights reserved.