gpt4 book ai didi

macos - NSTableView unhideRowsAtIndexes 崩溃

转载 作者:行者123 更新时间:2023-12-03 17:48:37 25 4
gpt4 key购买 nike

我正在创建一个分组的NSTableView,它加载得很好,并且按照我想要的方式加载了我的所有对象。

我还创建了折叠整个组部分(组行之间的行)的可能性,并使用添加的 hideRowsAtIndexes:withAnimation:unhideRowsAtIndexes:withAnimation:NSTableView (https://developer.apple.com/library/mac/releasenotes/AppKit/RN-AppKit/#10_11TableView)。

隐藏似乎总是有效,但取消隐藏某些行会崩溃。最后一行隐藏和取消隐藏都很好,前最后一行总是在取消隐藏时崩溃。仅当我有更多行可以显示时才会发生此行为。

Xcode给出的控制台崩溃日志:

0   CoreFoundation                      0x00007fff95d034f2 __exceptionPreprocess + 178
1 libobjc.A.dylib 0x00007fff9b506f7e objc_exception_throw + 48
2 CoreFoundation 0x00007fff95c1a7c5 -[__NSArrayM objectAtIndex:] + 245
3 AppKit 0x00007fff94e0496c -[NSTableRowData _updateVisibleViewsBasedOnUpdateItems] + 2701
4 AppKit 0x00007fff94e03dc5 -[NSTableRowData _updateVisibleViewsBasedOnUpdateItemsAnimated] + 241
5 AppKit 0x00007fff94d17d3f -[NSTableRowData _doWorkAfterEndUpdates] + 82
6 AppKit 0x00007fff94d1db49 -[NSTableView _doUpdatedWorkWithHandler:] + 251
7 AppKit 0x00007fff953209bc -[NSTableView hideRowsAtIndexes:withAnimation:] + 249
8 Testing NSTableView Collapse 0x0000000100004dfd -[AppDelegate collapse:] + 285
9 libsystem_trace.dylib 0x00007fff945ac07a _os_activity_initiate + 75
10 AppKit 0x00007fff94e75dbd -[NSApplication sendAction:to:from:] + 460
11 AppKit 0x00007fff94e87f12 -[NSControl sendAction:to:] + 86
12 AppKit 0x00007fff94e87e3c __26-[NSCell _sendActionFrom:]_block_invoke + 131
13 libsystem_trace.dylib 0x00007fff945ac07a _os_activity_initiate + 75
14 AppKit 0x00007fff94e87d99 -[NSCell _sendActionFrom:] + 144
15 libsystem_trace.dylib 0x00007fff945ac07a _os_activity_initiate + 75
16 AppKit 0x00007fff94e863be -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2693
17 AppKit 0x00007fff94ecef04 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 744
18 AppKit 0x00007fff94e84ae8 -[NSControl mouseDown:] + 669
19 AppKit 0x00007fff953d93c9 -[NSWindow _handleMouseDownEvent:isDelayedEvent:] + 6322
20 AppKit 0x00007fff953da3ad -[NSWindow _reallySendEvent:isDelayedEvent:] + 212
21 AppKit 0x00007fff94e19539 -[NSWindow sendEvent:] + 517
22 AppKit 0x00007fff94d99a38 -[NSApplication sendEvent:] + 2540
23 AppKit 0x00007fff94c00df2 -[NSApplication run] + 796
24 AppKit 0x00007fff94bca368 NSApplicationMain + 1176
25 Testing NSTableView Collapse 0x0000000100001352 main + 34
26 libdyld.dylib 0x00007fff89d675ad start + 1

是否有可能的解决方案或者这是一个框架问题?

代码: http://pastebin.com/esMH1LBF

最佳答案

由于这个问题也一直困扰着我,我做了一些挖掘,你知道什么?你是对的!这是一个 AppKit 错误。以下是 AppKit 10.13 Release Notes 的一些详细信息:

NSTableView

Hiding rows with the method -hideRowsAtIndexes:withAnimation: did not work correctly prior to macOS 10.13 when using standard row heights. This has been fixed for all applications on macOS 10.13. If you are targeting an older OS, it is recommended to use "variable row heights" by implementing -tableView:heightOfRow: and returning the desired row height; this will work around the bug with hidden row indexes.

Unhiding rows with the method -unhideRowsAtIndexes:withAnimation: did not work correctly prior to macOS 10.13 when using non-contiguous sets of rows. This has been fixed for all applications on macOS 10.13.

您会注意到第二段中提到了您的问题。

如果您正在针对早期版本的 macOS 进行开发,您可以执行以下操作:

func unhideRows(at indexes: IndexSet, animation: NSTableView.AnimationOptions = []) {
if #available(macOS 10.13, *) {
outlineView.unhideRows(
at: indexes,
withAnimation: animation
)
} else {
for range in indexes.rangeView {
outlineView.unhideRows(
at: IndexSet(integersIn: range),
withAnimation: animation
)
}
}
}

我希望我可以说这可以 100% 解决问题,但是,情况似乎并非如此。每隔一段时间,我似乎仍然会遇到这样的边界异常:

-[__NSArrayM objectAtIndex:]: index 11 beyond bounds [0 .. 10]

这可能是由于其他因素造成的,例如我的半复杂过滤代码,但因为我实际上无法看到Apple在其NSTableView方法中所做的事情,例如_updateVisibleViewsBasedOnUpdateItems,我只是不确定。

哦,好吧。我想我应该发布一个答案,以便其他遇到此问题的人知道该错误。祝你好运,旅途安全,我的地球同胞。

关于macos - NSTableView unhideRowsAtIndexes 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37616958/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com