NSTableView unhideRowsAtIndexes 崩溃 [英] NSTableView unhideRowsAtIndexes crashes

查看:28
本文介绍了NSTableView unhideRowsAtIndexes 崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am creating a grouped NSTableView that loads just fine and with all my objects the way I want to.

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

I also created the possibility to collapse entire group sections (the rows between group rows) and I use the hideRowsAtIndexes:withAnimation: and unhideRowsAtIndexes:withAnimation: that were added to NSTableView ( https://developer.apple.com/library/mac/releasenotes/AppKit/RN-AppKit/#10_11TableView).

隐藏似乎总是有效,但取消隐藏某些行会崩溃.最后一行隐藏和取消隐藏就好了,最后一行总是在取消隐藏时崩溃.只有当我有更多行可以显示时才会发生这种行为.

Hiding always seem to work, but unhiding crashes for some rows. The last row hides and unhides just fine, the before last always crashes on unhiding. This behaviour is only happening when I have more rows then possible to be displayed.

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

The console crash log given by 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

是否有可能的修复或这是一个框架问题?

Is there a possible fix or is this a framework problem?

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

推荐答案

由于这个问题也一直困扰着我,我做了一些挖掘,你知道什么?你是对的!这是一个 AppKit 错误.以下是 AppKit 的一些细节 10.13 发行说明:

As this problem has been plaguing me as well, I did some digging, and what do you know? You were right! It's an AppKit bug. Here are some details from AppKit's 10.13 Release Notes:

NSTableView

在 macOS 10.13 之前使用标准行高时,使用方法 -hideRowsAtIndexes:withAnimation: 隐藏行无法正常工作.这已针对 macOS 10.13 上的所有应用程序修复.如果您针对的是较旧的操作系统,建议通过实现 -tableView:heightOfRow: 并返回所需的行高来使用可变行高";这将解决隐藏行索引的错误.

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.

在 macOS 10.13 之前使用非连续行集时,使用方法 -unhideRowsAtIndexes:withAnimation: 取消隐藏行无法正常工作.此问题已针对 macOS 10.13 上的所有应用程序修复.

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.

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

You’ll notice in the second paragraph that your issue is mentioned.

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

If you’re developing for an earlier version of macOS, you can do the following:

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% 地解决问题,但是,情况似乎并非如此.每隔一段时间,我似乎仍然会遇到这样的边界异常:

I wish I could say that this fixes the problem 100% of the time, however, that doesn't seem to be the case. Every once in awhile, I still seem to run into bounds exceptions like this:

-[__NSArrayM objectAtIndex:]:索引 11 超出范围 [0 .. 10]

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

This could be due to other factors, such as my semi-complex filtering code, but as I can’t actually see what Apple’s doing in its NSTableView methods like _updateVisibleViewsBasedOnUpdateItems, I’m just not sure.

哦,好吧.我想我应该发布一个答案,以便其他在这个问题上苦苦挣扎的人知道这个错误.祝你好运,旅途平安,我的地球同胞.

Oh, well. I thought I should post an answer so other folks struggling with this issue are aware of the bug. Good luck and safe travels, my fellow earthling.

这篇关于NSTableView unhideRowsAtIndexes 崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆