swift - [NSView重新加载数据] : unrecognized selector sent to instance

标签 swift macos xcode9 nsoutlineview

我正在尝试通过在 splitView 的主端创建一个三级大纲 View 来学习一些 Swift 和 xcode。退出重新加载数据后代码崩溃(见下文)。它成功地通过了 NSOutlineViewDataSource numberOfChildrenOfItem 函数(我预计在发生其他事情之前会进行第二次传递),然后因“[NSView reloadData]:无法识别的选择器发送到实例”错误而崩溃。以下是可能的相关代码:

import Cocoa

//导入WebKit

class MasterViewController: NSViewController {

@IBOutlet weak var outlineView: NSOutlineView!

var categories = [Category]()

override func viewDidLoad() {
    super.viewDidLoad()

    // Do view setup here.
    if let filePath = Bundle.main.path(forResource: "Subjects", ofType:          "plist"){
        categories = Category.categoryList(filePath)
        print(categories)
    }
    self.outlineView.reloadData()
}

}

//这些是NSOutlineViewDataSource所需的扩展函数

/* 返回子代或孙代的数量。 需要注意的一件事: item 是可选的,并且为零 用于数据模型的根对象。在这种情况下, 类别为零;否则它将包含 对象的父对象。对于categoryItem对象, 项目将是一个类别。 */

extension MasterViewController: NSOutlineViewDataSource {
func outlineView(_ outlineView: NSOutlineView,
                 numberOfChildrenOfItem item: Any?) -> Int {

    if let category = item as? Category {

        return category.children.count
    }else if let categoryItem = item as? CategoryItem {

        return categoryItem.grandchildren.count
    }

    return categories.count
}

这是错误转储(我的知识不足以详细了解这一点):

[<ProbleMatic.Category: 0x600000048190>, <ProbleMatic.Category: 0x604000049630>, <ProbleMatic.Category: 0x60400004e100>]

2017-12-11 11:16:30.361189-0700 ProbleMatic[11382:4324228] -[NSView reloadData]: unrecognized selector sent to instance 0x6000001237a0

2017-12-11 11:16:30.361701-0700 ProbleMatic[11382:4324228] [General] -[NSView reloadData]: unrecognized selector sent to instance 0x6000001237a0

2017-12-11 11:16:30.365690-0700 ProbleMatic[11382:4324228] [General] (

    0   CoreFoundation                      0x00007fff390b300b
 __exceptionPreprocess + 171

    1   libobjc.A.dylib                     0x00007fff5fc91c76
 objc_exception_throw + 48

    2   CoreFoundation                      0x00007fff3914bcd4
 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132

    3   CoreFoundation                      0x00007fff390293f0
 ___forwarding___ + 1456

    4   CoreFoundation                      0x00007fff39028db8
 _CF_forwarding_prep_0 + 120

    5   ProbleMatic                         0x0000000100001cbc
 _T011ProbleMatic20MasterViewControllerC11viewDidLoadyyF + 1148

    6   ProbleMatic                         0x0000000100001e44
 _T011ProbleMatic20MasterViewControllerC11viewDidLoadyyFTo + 36

    7   AppKit                              0x00007fff3665b632
 -[NSViewController _sendViewDidLoad] + 97

    8   AppKit                              0x00007fff36bffd99
 _noteLoadCompletionForObject + 641

    9   AppKit                              0x00007fff365dfe21
 -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 2042

    10  AppKit                              0x00007fff366db13a
 -[NSNib _instantiateNibWithExternalNameTable:options:] + 679

    11  AppKit                              0x00007fff366dad96
 -[NSNib _instantiateWithOwner:options:topLevelObjects:] + 136

    12  AppKit                              0x00007fff366da06c
 -[NSViewController loadView] + 343

    13  AppKit                              0x00007fff36651f32
 -[NSViewController _loadViewIfRequired] + 75

    14  AppKit                              0x00007fff36651e9d
 -[NSViewController view] + 30

    15  AppKit                              0x00007fff3666c96b
 -[_NSSplitViewItemViewWrapper wrapView] + 94

    16  AppKit                              0x00007fff3666319e
 -[NSSplitViewController _setupSplitView] + 593

    17  AppKit                              0x00007fff36662d15
 -[NSSplitViewController viewDidLoad] + 155

    18  AppKit                              0x00007fff3665b632
 -[NSViewController _sendViewDidLoad] + 97

    19  AppKit                              0x00007fff3665206d
 -[NSViewController _loadViewIfRequired] + 390

    20  AppKit                              0x00007fff36651e9d
 -[NSViewController view] + 30

    21  AppKit                              0x00007fff36aa4cc7
 __67-[NSStoryboardEmbedSegueTemplate newDefaultPerformHandlerForSegue:]_block_invoke + 171

    22  AppKit                              0x00007fff36652015
 -[NSViewController _loadViewIfRequired] + 302

    23  AppKit                              0x00007fff36651e9d
 -[NSViewController view] + 30

    24  AppKit                              0x00007fff36eeaa23
 +[NSWindow windowWithContentViewController:] + 41

    25  AppKit                              0x00007fff3714c44d
 +[NSWindowController windowControllerWithContentViewController:] + 41

    26  AppKit                              0x00007fff36aa4888
 __66-[NSStoryboardShowSegueTemplate newDefaultPerformHandlerForSegue:]_block_invoke + 172

    27  AppKit                              0x00007fff36aa4602
 -[NSStoryboardShowSegueTemplate _perform:] + 275

    28  AppKit                              0x00007fff36da775a
 -[NSApplication(NSResponder) sendAction:to:from:] + 312

    29  AppKit                              0x00007fff3684d933
 -[NSControl sendAction:to:] + 86

    30  AppKit                              0x00007fff3684d85b
 __26-[NSCell _sendActionFrom:]_block_invoke + 136

    31  AppKit                              0x00007fff3684d761
 -[NSCell _sendActionFrom:] + 183

    32  AppKit                              0x00007fff3688ea18
 -[NSButtonCell _sendActionFrom:] + 97

    33  AppKit                              0x00007fff3684bfca
 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2438

    34  AppKit                              0x00007fff3688e75f
 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 777

    35  AppKit                              0x00007fff3684aa64
 -[NSControl mouseDown:] + 965

    36  AppKit                              0x00007fff36f46959
 -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 5891

    37  AppKit                              0x00007fff36f435b0
 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 2359

    38  AppKit                              0x00007fff36f4285c
 -[NSWindow(NSEventRouting) sendEvent:] + 497

    39  AppKit                              0x00007fff36da3617
 -[NSApplication(NSEvent) sendEvent:] + 307

    40  AppKit                              0x00007fff36604d9d
 -[NSApplication run] + 812

    41  AppKit                              0x00007fff365d3f1a
 NSApplicationMain + 804

    42  ProbleMatic                         0x000000010000f50d
 main + 13

    43  libdyld.dylib                       0x00007fff60881115
 start + 1

    44  ???                                 0x0000000000000003
 0x0 + 3

)

有什么建议吗?提前致谢。

最佳答案

您的 socket 可能连接到的不是大纲 View (很可能是其 super View )。

您可以通过...检查

  • 将鼠标悬停在 socket 圆圈上
  • Ctrl 单击 View 层次结构中的大纲 View 。

enter image description here

关于swift - [NSView重新加载数据] : unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47759876/

相关文章:

ios - 如何将 UILabel 的属性反射(reflect)给另一个?

iOS 导航后退按钮

ios - VFL 表达式未按预期翻译 IB 约束

macos - 加载 TIFF 时 NSImage initWithContentsOfURL 缺少 alpha channel

swift - 为 MacOS 命令行工具设置应用程序组?

c++ - 如何在 Xcode 9.3 中显示 C++ 代码文档?

swift - 如何区分 XCode 9 中的 AnyObject(或 Int)类型 - 新的 Swift 编译器

swift - 当发布者失败类型不等效时如何使用 CombineLates?

python - 使用 python 请求的 SSLError

swift:索引超出范围